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

What does pointer mean?

1042


What is boolean example?

960


How do you add an arraylist to an array in java?

967


Can a lock be acquired on a class in java programming?

987


Is it necessary for the port addresses to be unique? Explain with reason.

1012


whar are the draw backs of programming lang step by step in Clang and next in C++ and next and in Java nad in .Net

2088


What is xslt in java?

969


How do you do descending order in java?

956


What is contract between hashcode and equal method?

1025


What is thread safe singleton?

941


What is the format specifier?

915


Is a copy constructor?

1048


What is r in java?

1043


What is array initialization in java?

1073


Is set ordered in java?

970