Map and List are two common data structures available in Java The main difference between Map (HashMap, ConcurrentHashMap or TreeMap) and List is that Map holds two objects key and value while List just holds one object which itself is a value How to Convert Map into List in Java with Example import java.util.ArrayList; public class JavamapToList { } Output Size of javaMapsMap: 4
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map.Entry;
static boolean result;
public static void main(String[] args)
{
HashMap<String, String> javaMaps= new HashMap<String, String>();
// preparing hashmap with keys and values
javaMaps.put("JAVA1", "JAVA 1");
javaMaps.put("JAVA2", "Core Java");
javaMaps.put("Java3", "JEE");
javaMaps.put("Java4", "Spring");
System.out.println("Size of javaMapsMap: " + javaMaps.size());
//Converting HashMap keys into ArrayList
List<String> keyList = new ArrayList<String>(javaMaps.keySet());
System.out.println("Size of Key list from Map: " + keyList.size());
//Converting HashMap Values into ArrayList
List<String> valueList = new ArrayList<String>(javaMaps.values());
System.out.println("Size of Value list from Map: " + valueList.size());
List<Entry> entryList = new ArrayList<Entry>(javaMaps.entrySet());
System.out.println("Size of Entry list from Map: " + entryList.size());
}
Size of Key list from Map: 4
Size of Value list from Map: 4
Size of Entry list from Map: 4
How to create Arraylist from Array in Java
How to convert ArrayList to Array in Java
How to Sort ArrayList of Object Type in Java?
What is Difference Between "==" and "equals" method in Java
What is difference between HashMap and HashSet in Java
What is Java Collections Framework?
How to join Multiple String Objects in Java 8
What is a Collection ?
How to Fetch System UUID with Java Program?
Java Thread - How to create Threads in Java?
How to Convert a Map to a List in Java Example
How to split a string in Java