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 is the purpose of final keyword and when to use it?

940


Differentiate between the constructors and methods in java?

891


how can i use a nonsynchronized hashtable?

2525


How many ways can we create singleton class?

914


What are recursive functions?

982


What is the difference between superclass and subclass?

1082


What is the use of isempty in java?

962


What do you mean by inner class in java?

1009


What is difference between fileinputstream and filereader in java?

986


Can we use String with switch case?

1106


What is preflight request?

940


What does main method?

928


What are the four integer types supported by java?

975


Which package has light weight components?

931


What is meant by JVM? Is JVM platform independent or not?

1004