public class Repeatedcount
{
public static void main(String...args)
{
List<String> userNameList = new ArrayList();
userNameList.add("ram");
userNameList.add("som");
userNameList.add("som");
userNameList.add("som");
userNameList.add("ram");
Map<String, Integer> mp = new HashMap<String, Integer>();
for (String userName : userNameList) {
Integer count = mp.get(userName);
mp.put(userName, count == null ? 1 : ++count);
System.out.println(mp);
}
}
{
public static void main(String...args)
{
List<String> userNameList = new ArrayList();
userNameList.add("ram");
userNameList.add("som");
userNameList.add("som");
userNameList.add("som");
userNameList.add("ram");
Map<String, Integer> mp = new HashMap<String, Integer>();
for (String userName : userNameList) {
Integer count = mp.get(userName);
mp.put(userName, count == null ? 1 : ++count);
System.out.println(mp);
}
}
No comments:
Post a Comment