package com.concretepage;
import java.util.HashMap;
import java.util.Map.Entry;
import java.util.Set;
import java.util.Iterator;
import java.util.LinkedHashMap;
public class HashMaptoCharArray {
public static void main(String[] args) {
HashMap hmap = new LinkedHashMap<>();
hmap.put("One", "1");hmap.put("Two", "2");
hmap.put("Three", "3");hmap.put("Four","4");
hmap.remove("One", "1");
Set<Entry<String, String>> reference = hmap.entrySet();
Iterator<Entry<String, String>> iterator1 = reference.iterator();
while(iterator1.hasNext()) {
Entry<String, String> entry1 = iterator1.next();
System.out.print(entry1.getValue());System.out.print(" ");System.out.print(entry1.getKey());
System.out.println();
}
System.out.println("************************************************************************");
//hmap.remove("Two");
//hmap.remove("Two","2");
//hmap.replace("Two", "22");
//hmap.replace("Two", "2", "22000rs");
Set<Entry<String, String>> referenceAgain = hmap.entrySet();
Iterator<Entry<String, String>> iterator2 = referenceAgain.iterator();
while(iterator2.hasNext()) {
Entry<String, String> entry2 = iterator2.next();
System.out.print(entry2.getValue());System.out.print(" ");System.out.print(entry2.getKey());
System.out.println();
}
System.out.println("************************************************************************");
}
}
import java.util.HashMap;
import java.util.Map.Entry;
import java.util.Set;
import java.util.Iterator;
import java.util.LinkedHashMap;
public class HashMaptoCharArray {
public static void main(String[] args) {
HashMap hmap = new LinkedHashMap<>();
hmap.put("One", "1");hmap.put("Two", "2");
hmap.put("Three", "3");hmap.put("Four","4");
hmap.remove("One", "1");
Set<Entry<String, String>> reference = hmap.entrySet();
Iterator<Entry<String, String>> iterator1 = reference.iterator();
while(iterator1.hasNext()) {
Entry<String, String> entry1 = iterator1.next();
System.out.print(entry1.getValue());System.out.print(" ");System.out.print(entry1.getKey());
System.out.println();
}
System.out.println("************************************************************************");
//hmap.remove("Two");
//hmap.remove("Two","2");
//hmap.replace("Two", "22");
//hmap.replace("Two", "2", "22000rs");
Set<Entry<String, String>> referenceAgain = hmap.entrySet();
Iterator<Entry<String, String>> iterator2 = referenceAgain.iterator();
while(iterator2.hasNext()) {
Entry<String, String> entry2 = iterator2.next();
System.out.print(entry2.getValue());System.out.print(" ");System.out.print(entry2.getKey());
System.out.println();
}
System.out.println("************************************************************************");
}
}
No comments:
Post a Comment