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 an object's lock and which object's have locks in java programming?

1101


Is java pass by value or pass by reference?

1027


What is arrays aslist in java?

991


Which collection is thread safe in java?

1034


Why does the integer quotient -0/3 yield 0, but the double quotient -0.0/3.0 yields – 0.0?

1104


What does void * mean?

1104


What is the difference between delete and delete[]

1639


what is the volatile modifier for? : Java thread

1056


Give an example of use of pointers in java class.

1068


What is space character in java?

1168


What was java originally called?

998


what are three ways in which a thread can enter the waiting state? Or what are different ways in which a thread can enter the waiting state? : Java thread

1027


Why does java not support pointers?

1169


What is the use of hashmap in java?

1133


Can you declare a private method as static?

1190