

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
List.replaceAll(UnaryOperator<E> operator) method in Java
The replaceAll() method of the List interface accept an object of the UnaryOperator representing a particular operation, performs the specified operation on all the elements of the current list and replaces the existing values in the list with their respective results.
Example
import java.util.ArrayList; import java.util.function.UnaryOperator; class Op implements UnaryOperator<String> { public String apply(String str) { return str.toUpperCase(); } } public class Test { public static void main(String[] args) throws CloneNotSupportedException { ArrayList<String> list = new ArrayList<>(); list.add("Java"); list.add("JavaScript"); list.add("CoffeeScript"); list.add("HBase"); list.add("OpenNLP"); System.out.println("Contents of the list: "+list); list.replaceAll(new Op()); System.out.println("Contents of the list after replace operation: \n"+list); } }
Output
Contents of the list: [Java, JavaScript, CoffeeScript, HBase, OpenNLP] Contents of the list after replace operation:[JAVA, JAVASCRIPT, COFFEESCRIPT, HBASE, OPENNLP]
- Related Questions & Answers
- How to use UnaryOperator<T> interface in lambda expression in Java?
- Collections.replaceAll() method and List.replaceAll() method in Java
- What is the operator <=> in MySQL?
- '></a></li></ul><i>xssi</i>
- Custom UnaryOperator implementation in java.
- What does the method addFirst(E e) do in java?
- What does the method addLast(E e) do in java?
- Should I use <img>, <object>, or <embed> for SVG files?
- What are the >> and << operators in Python?
- What is the correct way of using <br>, <br/>, or <br /> in HTML?
- Overloading stream insertion (<<) and extraction (>>) operators in C++
- How to get ArrayList<String> to ArrayList<Object> and vice versa in java?
- How to implement ToIntFunction<T> using lambda and method reference in Java?
- How to implement LongFunction<R> using lambda and method reference in Java?
- How to use Predicate<T> and BiPredicate<T, U> in lambda expression in Java?
Advertisements