Advertisement
Guest User

Untitled

a guest
Mar 27th, 2015
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. public class HashMapExample {
  2. public static void main(String[] args) {
  3. HashMap<String, String> hasmap = new HashMap<String, String>();
  4. hasmap.put("1", "Java");
  5. hasmap.put("2", ".Net");
  6. hasmap.put("3", "C++");
  7. hasmap.put("4", "Pearl");
  8. hasmap.put("5", "PHP");
  9.  
  10. for (Entry<String, String> entry : hasmap.entrySet()) {
  11.  
  12. System.out.println("For Loop Get Key"+entry.getKey());
  13. System.out.println("For Loop Get Value"+entry.getValue());
  14.  
  15. }
  16. Set set = hasmap.entrySet();
  17. Iterator itr = set.iterator();
  18. while(itr.hasNext()){
  19. Map.Entry map = (Entry) itr.next();
  20. System.out.println(map.getKey());
  21. System.out.println(map.getValue());
  22. }
  23.  
  24.  
  25. }
  26.  
  27. }
  28.  
  29. for (String str : array) {
  30. System.out.println(str);
  31. }
  32.  
  33. Iterator<String> arrayItr = array.iterator();
  34. while (arrayItr.hasNext()) {
  35. String str = arrayItr.next();
  36. System.out.println(str);
  37. }
  38.  
  39. for(Iterator<String> i = someList.iterator(); i.hasNext(); ) {
  40. String item = i.next();
  41. System.out.println(item);
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement