ALLInterview.com :: Home Page            
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
Google
   
 
Categories >> Software >> Java Related >> Java J2EE >> Core Java
 
 


 

 
 Core Java interview questions  Core Java Interview Questions (1721)
 Advanced Java interview questions  Advanced Java Interview Questions (331)
 Swing interview questions  Swing Interview Questions (44)
 EJB interview questions  EJB Interview Questions (134)
 Servlets interview questions  Servlets Interview Questions (255)
 Struts interview questions  Struts Interview Questions (196)
 JDBC interview questions  JDBC Interview Questions (187)
 JMS interview questions  JMS Interview Questions (9)
 SunOne interview questions  SunOne Interview Questions (3)
 J2EE interview questions  J2EE Interview Questions (71)
 Weblogic interview questions  Weblogic Interview Questions (146)
 Websphere interview questions  Websphere Interview Questions (14)
 Java Networking interview questions  Java Networking Interview Questions (20)
 Java J2EE AllOther interview questions  Java J2EE AllOther Interview Questions (87)
Question
there are some duplicate values in ArrayList, how U'll get
that array with out duplicate?
 Question Submitted By :: Core-Java
I also faced this Question!!     Answer Posted By  
 
Answer
# 1


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
Sai
 
Answer
# 2
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
Phani Raju
 
 
 
Answer
# 3
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
Shilpa
 
Answer
# 4
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
Banti
 

 
 
 
Other Core Java Interview Questions
 
  Question Asked @ Answers
 
what are upcasting and downcasting?   4
What is adapter class?   12
if i have one string class then how can you achive this class functionality of this class? Fidelity 3
What are the two major components of JDBC? Mind-Tree 5
why top level class could not be static L&T 2
How does Vector implement synchronization? Ness-Technologies 4
How can we create a object of a class without using new operator. Nokia 1
which of tha following is not a thread safe class? a) ArrayList b)Vector c)HashTable d)None   17
strings in java are objects.why?   2
Can we add two byte variables and assign the result to a byte variable ? b=b1+b2 where b,b1,b2 are byte types TCS 4
what is main difference between architecture,framework and design pattren   3
How HashMap implemented in java? how it internally works when values are added or searched from hashMap?What is the difference betweenthe implementation of hashmap and Linked Hashmap? IBM 3
 
For more Core Java Interview Questions Click Here 
 
 
 
 
 


   
Copyright Policy  |  Terms of Service  |  Articles  |  Site Map  |  RSS Site Map  |  Contact Us
   
Copyright 2013  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  KalAajKal.com