collections
I am not abe to execute the program..please help
import java.util.*;
public class AA {
public static void main(String[]args){
String[] things = {"hat ","pencil ","bottle ","laser"};
List<String> list1 = new ArrayList<String>();
//add items to the list
for(String x:things)
list1.add(x);
String[] morethings = {"pencil","bottle"};
List<String> list2 = new ArrayList<String>();
//add items to the list
for(String y:morethings)
list2.add(y);
//print list 1
for(int i=0;i<list1.size();i++){
System.out.printf("%s",list1.get(i));
}
editlist(list1,list2);
System.out.println();
//print list 1
for(int i=0;i<list1.size();i++){
System.out.printf("%s",list1.get(i));
}
}
public static void editlist(Collection<String> l1,Collection<String> l2){
Iterator<String>it=l2.iterator();
while(it.hasNext()){
if(l2.contains(it.next()))
it.remove();
}
}
}
View Answers
July 12, 2011 at 5:55 PM
Do you want to remove the elements the elements from list1 which are present in list2?
July 12, 2011 at 7:05 PM
yes sir..i was expecting the answer like this
hat pencil bottle laser
hat laser
but its displaying,
hat pencil bottle laser
hat pencil bottle laser..
So please help me to get the output..
July 13, 2011 at 9:41 AM
eagerly waiting for ur reply..pls respond back sooon
Related Tutorials/Questions & Answers:
CollectionsCollections Hi,
Please send a study material on
collections.../java/jdk6/introduction-
collections-api.shtml
http://www.roseindia.net/javacodeexamples/index.shtml
http://www.devmanuals.com/tutorials/java/
collections/index.html
collectionscollections in
collections can we perform binarysearch on arraylist elements without sorting them
Advertisements
collectionscollections why we need collections.when we will use
collections in our applications
Collections APICollections API hello,
What is the
Collections API?
hiADS_TO_REPLACE_1
The
Collections API is a set of classes and interfaces that support operations on
collections of objects
java collectionsjava collections what are all the methods and things added for
collections in java5 and java6 please kindly reply me as soon as possible
Collections FrameworkCollections Framework Sir, We know that both HashMap & Hashtable is using for same purposes i.e Used for storing keys-values pair. But there is some difference between this two class that are
1)Hashtable is synchronized
collections in javacollections in java please explain me the flow of this program..i m getting o/p as 2 1 1..y not 2 1 0..is it that if we change the i2 value,it doesnt remove.
import java.util.*;
public class Mapit {
public static void main
java collections achieve this plz without using stringtokenizer with any
collections!!!
Hibernate Criteria With Collections ExampleHibernate Criteria With
Collections Example Good code of Hibernate Criteria With
Collections Example.
Thanks
Example program of using Hibernate Criteria With
Collections in your Java project.
Check the tutorial
collections - Java Interview Questionscollections The Java
Collections API Hi friend,
Java
Collections of API (Application Programming Intreface) Consists of several.../java/jdk6/introduction-
collections-api.shtml
Thanks