package collections;
import java.util.HashMap;
import java.util.Map;
public class HashMapEx {
public static void main(String[] args) {
//Here String is key and Integer is value
Map<String,Integer> hm=new HashMap<String,Integer>();
//Enter values to table from Command line arguments
for(String s:args)
{
Integer a=hm.get(s);
hm.put(s,(a==null)?1:a+1);
}
System.out.println("Size: "+hm.size());
System.out.println("Distinct Words: "+hm);
}
}
import java.util.HashMap;
import java.util.Map;
public class HashMapEx {
public static void main(String[] args) {
//Here String is key and Integer is value
Map<String,Integer> hm=new HashMap<String,Integer>();
//Enter values to table from Command line arguments
for(String s:args)
{
Integer a=hm.get(s);
hm.put(s,(a==null)?1:a+1);
}
System.out.println("Size: "+hm.size());
System.out.println("Distinct Words: "+hm);
}
}
0 comments:
Post a Comment