Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


there are some duplicate values in ArrayList, how U'll get
that array with out duplicate?

Answers were Sorted based on User's Feedback



there are some duplicate values in ArrayList, how U'll get that array with out duplicate?..

Answer / sai



ArrayList list = new ArrayList();
list.add("a");
list.add("b");
list.add("a");
list.add("c");
list.add("b");
HashSet set = new HashSet(list);
list.clear();
list.addAll(set);
System.out.println("ArrayList : ");
for (Object data : list) {
System.out.println(data);

Is This Answer Correct ?    13 Yes 2 No

there are some duplicate values in ArrayList, how U'll get that array with out duplicate?..

Answer / phani raju

ArrayList list = new ArrayList();
list.add("a");
list.add("b");
list.add("a");
list.add("c");
list.add("b");
LinkedHashSet lset = new LinkedHashSet
(list);
list.clear();
list.addAll(lset);
System.out.println("ArrayList : ");
for (Object data : list) {
System.out.println(data);

Is This Answer Correct ?    5 Yes 0 No

there are some duplicate values in ArrayList, how U'll get that array with out duplicate?..

Answer / shilpa

List<Integer> arlList=new ArrayList<Integer>();
arlList.add(20);
arlList.add(2);
arlList.add(1);
arlList.add(6);
arlList.add(6);
Set<Integer> tr=new TreeSet<Integer>(arlList);
Iterator<Integer> iterator=tr.iterator();
while(iterator.hasNext()){
System.out.println(iterator.next());
}

Is This Answer Correct ?    4 Yes 0 No

there are some duplicate values in ArrayList, how U'll get that array with out duplicate?..

Answer / banti

public void removeDuplicateDataFromArrayList(){
ArrayList<String> al = new ArrayList<>();
al.add("a");
al.add("b");
al.add("c");
al.add("c");
al.add("a");

HashSet<String> hs = new HashSet<>();
hs.addAll(al);
al.clear();
al.addAll(hs);
System.out.println("The ArrayList values are :"+ al);

// Or

System.out.println("ArrayList : ");
for (Object data : al) {
System.out.println(data);
}

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Core Java Interview Questions

List the interfaces which extends collection interface?

0 Answers  


Can an interface be final?

0 Answers  


Why do we need wrapper class?

0 Answers  


what is mean by method signature?

5 Answers   Satyam,


Every class extends object but why it is not possible for every object to invoke clone() method. ideally protected methods should be accessible from sub classes. isn't it?

2 Answers  


What is access modifiers?

1 Answers   Cap Gemini,


what is the difference b/w design pattern and architecture

4 Answers   Covansys,


when should you use stringbuilder class in a program?

0 Answers  


Can java arraylist hold different types?

0 Answers  


Is intellij better than eclipse?

0 Answers  


What is prime number in java?

0 Answers  


Explain when we should make an instance variable private.

0 Answers  


Categories