Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class HashMapExample {
- public static void main(String[] args) {
- HashMap<String, String> hasmap = new HashMap<String, String>();
- hasmap.put("1", "Java");
- hasmap.put("2", ".Net");
- hasmap.put("3", "C++");
- hasmap.put("4", "Pearl");
- hasmap.put("5", "PHP");
- for (Entry<String, String> entry : hasmap.entrySet()) {
- System.out.println("For Loop Get Key"+entry.getKey());
- System.out.println("For Loop Get Value"+entry.getValue());
- }
- Set set = hasmap.entrySet();
- Iterator itr = set.iterator();
- while(itr.hasNext()){
- Map.Entry map = (Entry) itr.next();
- System.out.println(map.getKey());
- System.out.println(map.getValue());
- }
- }
- }
- for (String str : array) {
- System.out.println(str);
- }
- Iterator<String> arrayItr = array.iterator();
- while (arrayItr.hasNext()) {
- String str = arrayItr.next();
- System.out.println(str);
- }
- for(Iterator<String> i = someList.iterator(); i.hasNext(); ) {
- String item = i.next();
- System.out.println(item);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement