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 a stringbuilder?
Can a lock be acquired on a class in java programming?
What are serialization and deserialization?
Why enumeration is faster than iterator?
What are drawbacks of singleton class?
How does the java compiler work?
How can we use primitive data types as objects?
What is the file type?
How many boolean functions are there?
Explain the differences between static and dynamic variables?
Difference between operator overloading and function overloading
what do you mean by classloader in java?
Define class?
Why is java logo a cup of coffee?
What is a 16 bit word?