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


Please Help Members By Posting Answers For Below Questions

What is the static block?

591


make a method which any number and any type of argument and print sum of that arguments.....

1388


what is thread? : Java thread

561


What is int argc char * argv?

575


What is the difference between length and length () in java?

533






Why is multiple inheritance not supported in java?

571


How do you classify Dialog Box?

658


Can you sort a list in java?

533


What is the importance of static variable?

596


Explain public static void main(string args[]).

573


Explain about the select method with an example?

594


Can we have any code between try and catch blocks?

567


Is void a data type?

540


How do I get 64 bit java?

540


What is the difference between an array and an array list?

512