6 7 8 Output: 1 2 3 4 5 6 7 8. I want to remove all the duplicate elements in an arraylist. ArrayList removeDuplicates(ArrayList list) // Create a new ArrayList ArrayList newList = new ArrayList; // Traverse through the first list for (T element: list) // If this element is not present in newList then add it if.
![Remove Remove](/uploads/1/2/5/7/125740675/561154482.jpg)
Few Java examples to convert a
Map
to a List
1. Map To List
For a simple
Map
to List
conversion, just uses the below code :Output
Java 8 – Map To List
For Java 8, you can convert the
Map
into a stream, process it and returns it back as a List
ConvertMapToList.java
Output
3. Java 8 – Convert Map into 2 List
This example is a bit extreme, uses
map.entrySet()
to convert a Map
into 2 List
Output