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 Access Specifiers and Access Modifiers. TCS 6
Explain the difference between the Boolean & operator and the && operator?   1
give me the answer of this code class A extnds String This code we can write r not in Java? Explain?   4
can we access the method of class without creating the object of the class   3
what is jndi? TCS 1
Why Java is not purely object oriented? Persistent 49
What is casting?   3
Hey buddy.. can you please tell me about the use of marker interface? And is there any link between marker interface and factory methods? Thanks in advance.   2
Write java code to print "Hello how are you" Thread1 should have "Hello" Thread2 should have "how are you" both the threads should start at the same time Huawei 4
why interfaces are faster than abstract classes?   4
what is the difference between applet and swing and gui application in java . What we do with the collections set and list interface Phoenix-Technologies 2
What is the difference between method and constructor ?   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