How to place a map inside a list interface in Java?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • srikanthbabu
    New Member
    • Jan 2011
    • 5

    How to place a map inside a list interface in Java?

    can i place a map inside a list interface in java please help me with a example
  • Dheeraj Joshi
    Recognized Expert Top Contributor
    • Jul 2009
    • 1129

    #2
    Yes. Possible.

    Code:
    List l = new LinkedList();
    		
    HashMap mp = new HashMap();
    mp.put("1", "one");
    mp.put("2", "two");
    l.add(mp);
    		
    for (Object object : l) {
    	HashMap hp = (HashMap)object;
            if(hp.get("1").equals("one")){
                    System.out.println("True");
    	}
    	else{
    		System.out.println("False");
    	}
    }
    Regards
    Dheeraj Joshi

    Comment

    • srikanthbabu
      New Member
      • Jan 2011
      • 5

      #3
      thanku very much Dheeraj

      Comment

      • srikanthbabu
        New Member
        • Jan 2011
        • 5

        #4
        for (Object object : l)
        what is the meaning of this expression

        Comment

        Working...