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 are different types of multitasking?
Can we make the abstract methods static in java?
Variables used in a switch statement can be used with which datatypes?
What is difference between this and super keyword?
What is the full form of jpeg?
What is immutable data?
What is the difference between a break statement and a continue statement?
What is the buffer limit?
Why parameters should be passed by reference?
Is hashset ordered java?
what invokes a threads run() method? : Java thread
Define how does a try statement determine which catch clause should be used to handle an exception?
What is the base class in java from which all classes are derived?
What do you understand by Header linked List?
What is the difference between abstract classes and interfaces?