I have a Arraylist object, it has duplecate values also. Now
question is i want delete duplecate data in that objet with
out using Set?
Answer Posted / s.ramesh
import java.util.ArrayList;
public class DemoTest
{
public static void main (String args[])
{
ArrayList arrList = new ArrayList();
arrList.add("One");
arrList.add("Two");
arrList.add("Two");
arrList.add("Three");
arrList.add("Four");
arrList.add("One");
arrList.add("Four");
arrList.add("One");
arrList.add("Six");
arrList.add("One");
arrList.add("Ten");
arrList.add("Three");
arrList.add("One");
arrList.add("Two");
arrList.add("One");
arrList.add("One");
for(int i=0;i<arrList.size();i++)
{
String ele = (String) arrList.get(i);
boolean f = true;
while(f)
{
int firstInd = arrList.indexOf(ele);
int lastInd = arrList.lastIndexOf(ele);
if(firstInd==lastInd)
{
f=false;
}
else
{
arrList.remove(lastInd);
}
}
}
for(int i=0;i<arrList.size();i++)
System.out.println((String)arrList.get(i));
}
}
| Is This Answer Correct ? | 14 Yes | 1 No |
Post New Answer View All Answers
Explain creating threads by extending thread class ?
How do you use substring in java?
What is a hashmap used for?
What is the major difference between linkedlist and arraylist?
Is array an object in java?
What is java autoboxing?
How can we achieve thread safety in java?
When will you define a method as static?
How is tree Mirroring implemented?
How is hashcode calculated in java?
How can we pass argument to a function by reference instead of pass by value?
What is the purpose of an interface?
What are constructors in java?
What is stream api in java8?
Is hashset ordered java?