You need to sign in to do that
Don't have an account?
subbu123.pbt@gmail.com
display the duplicate values present in a list.
List li=new List();
li.add("12");
li.add("13");
li.add("14");
li.add("12");
li.add("14");
My Requirment Is Display only Duplicate values like 12 , 14 values , what i do ?
ple guide me , how to do . thank u in advanced.
Hi,
You can try this:
List li=new List();
li.add("12");
li.add("13");
li.add("14");
li.add("12");
li.add("14");
Set set = new Set();
List duplicateList = new List();
for(String s: li) //assuming the data is String
{
if(set.contains(s){
duplicateList.add(s)
}else{
set.add(s);
}
}
//print duplicate list from duplicateList variable.
regards,
Hi,
Try this out:
Set.add() returns a Boolean, which is true if it was successfully added to the set. If the object was already in the set, it will be false.
Oh...The code above removes the duplicates, but if you want to retain the duplicates, use the bellow code: