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 (1722)
 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 (147)
 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 is the meaning of java.lang and java.util   6
how many design pattern r there? and wht design pattern u use and why ? HP 5
what is use of session tracking ?with example? Photon 1
what is the need of the Ajax? iFlex 5
What is onClassLoader in java? Cap-Gemini 5
What is the argument type of main() method?   2
what is language and it responsibilities   1
How to convert a string to long?   2
Which One is optimal to choose ? Syncronized hash map or Hash table with single thread model? How can a hash map syncronized with out using syncrozed blocks in programm? Four-soft 3
what is purpose of collections.unmodified() method..? Accenture 1
In Inheritance if we are implementing Multi level inheritance and all class having same name of variable and now i want to access each class variable and how it is possible?   2
What is the difference between Java Bean and Java Class.?   2
 
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