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
Java is Pass by Value or Pass by Reference?
Why inputstreamreader is used in java?
How can you make sure that your singleton class will always return single instance in multi-threaded environment?
What is the difference between static method and instance method in Java?
Describe the process as to how substring() methodology mechanisms in java.
What is a null check?
When arithmeticexception is thrown?
What is an empty list in java?
How do I enable java in safari?
What is treeset in java?
Explain the difference between arraylist and linkedlist in java?
Can a abstract class be defined without any abstract methods?
What is factor r?
Considering notepad/ie or any other thing as process, what will happen if you start notepad or ie 3 times? Where 3 processes are started or 3 threads are started?
What are the features of junit?