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

In Java list the methods that can be overridden?

1013


How big is a boolean?

1036


What do the thread?class methods run() and start() do?

1038


What are generic methods?

980


How to create com object in Java?

1083


Can singleton class be serialized?

953


Explain the overview of UDP messaging.

1129


Why do we need data serialization?

998


What is the purpose of main function in java?

1031


what is collatration?

3291


What is * argv?

1240


Explain the reason behind ending a program with a system.exit(0)?

1090


What is the difference between a switch statement and an if statement?

1092


Which arithmetic operations can result in the throwing of an arithmeticexception?

1027


Explain the Propertie sof class?

1053