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 if constructor is protected in java?
What are encapsulation, inheritance and polymorphism?
Why do we use return statement?
What is the synonym of string?
Variables used in a switch statement can be used with which datatypes?
Does A Class Inherit The Constructors Of Its Superclass?
What is the difference between scrollbar and scrollpane?
How to create a base64 decoder in java8?
Give differences between Quicksort &Mergesort. When should these sorts be used andwhat is their running time in java?
Why string is immutable or final in java
What are voids?
What is the difference between and ?
How do you square a number in java?
Which class represents the socket that both the client and server use to communicate with each other?
How are the elements of a gridbaglayout organized in java programming?