Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Convert Map to List

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 241
    Comment on it

    Map and List are the two commonly used data structures
    Here I am writing way to convert Map to List.
    Basically Map holds two things are key and value on the other hand list holds only values.
    Both Map and List allow duplicate data.

    Below is the example:

    public class MapToListConversion{ 
    
    public static void main(String... args) { 
        HashMap<String, String> empMap = new HashMap<String, String>(); 
        empMap.put("emp name", "abc"); 
        empMap.put("emp id", "10022"); 
        empMap.put("emp designation", Software Engg"); 
        empMap.put("experience", "5 Years); 
    
        System.out.println("Size of Employee Map: " + empMap.size()); 
    
        List<String> testList = new ArrayList<String>( empMap.keySet()); 
        System.out.println("Size of test List keys : " + testList.size()); 
    
        List<String> testListValues = new ArrayList<String>( empMap.values()); 
        System.out.println("Size of list values: " + testListValues.size()); 
    
    } 
    
    } 

    O/P:
    Size of Employee Map: 4
    Size of test List keys : 4
    Size of list values: 4

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: