Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

how to identify duplicate values in arraylist

Answer Posted / srikanth m

List<String> list = new ArrayList<String>();
list.add("abc");
list.add("def");
list.add("abc");




HashMap<String, Integer> map = new HashMap<String, Integer>();




for (String str : list) {
Integer c = (Integer) map.get(str);
if (c == null || c == 0) {
map.put(str, 1);
} else {
map.put(str, ++c);
}
}
System.out.println(map);

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Which is better arraylist or vector?

1066


What is the difference between instanceof and isinstance?

1128


What is the difference between the boolean & operator and the && operator in java programming?

1097


Write a program to print fibonacci series up to count 10.

969


why Interface used?

1032


Can we use different return types for methods when overridden?

1063


What interface is extended by awt event listeners?

1104


Explain the difference between throw and throws in java?

1062


Where import statement is used in a java program?

1191


What is java beans?

1050


What is a parameter used for?

1007


How can we access some class in another class in java?

1054


List the interfaces which extends collection interface?

1000


What is a vector in java?

1091


What is the program compilation process?

1191