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
What is equals method in java?
What is the use of math abs in java?
What is a parameter used for?
Is empty set an element of empty set?
What are implicit objects in java?
What is void in java?
What is final method in java?
Mention some features of java?
Why is the type for real numbers called double?
Explain about member inner classes?
How to perform selection sort in java?
what is predefined function in java?
What is difference between protected and private?
Why is java called the platform independent programming language?
How to make a non daemon thread as daemon?