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 if constructor is protected in java?

554


What are encapsulation, inheritance and polymorphism?

521


Why do we use return statement?

533


What is the synonym of string?

527


Variables used in a switch statement can be used with which datatypes?

507






Does A Class Inherit The Constructors Of Its Superclass?

530


What is the difference between scrollbar and scrollpane?

604


How to create a base64 decoder in java8?

549


Give differences between Quicksort &Mergesort. When should these sorts be used andwhat is their running time in java?

670


Why string is immutable or final in java

601


What are voids?

528


What is the difference between and ?

501


How do you square a number in java?

545


Which class represents the socket that both the client and server use to communicate with each other?

562


How are the elements of a gridbaglayout organized in java programming?

512