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 the static block?
make a method which any number and any type of argument and print sum of that arguments.....
what is thread? : Java thread
What is int argc char * argv?
What is the difference between length and length () in java?
Why is multiple inheritance not supported in java?
How do you classify Dialog Box?
Can you sort a list in java?
What is the importance of static variable?
Explain public static void main(string args[]).
Explain about the select method with an example?
Can we have any code between try and catch blocks?
Is void a data type?
How do I get 64 bit java?
What is the difference between an array and an array list?