Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Development-process java collection - creating and comparing lists using Java
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Rohan
java collection - creating and comparing lists using Java
1 Answer(s)      6 years and 10 months ago
Posted in : Development process


How to compare two list in java? and i have to create two more list from old two list. Comparing and Creating new list in Java Java Example code for creating and comparing lists using Java


Advertisement
View Answers

February 26, 2008 at 5:50 PM


Comparing and Creating new list in Java

Java Example code for creating and comparing lists using Java.

import java.util.*;

public class TwoList{
static List<String> makeList(int n) {
List<String> list = new ArrayList<String>(n);
while (n--> 0){
list.add(makeString());
}
return list;
}
static final Random random = new Random();
static String makeString() {
char [] s = new char[8];
for (int i=0; i< s.length; i++) {
s[i] = (char) ('A' + random.nextInt(3));
}
return new String(s);
}
static List<String> list1 = makeList(1000);
static List<String> list2 = makeList(5000);

public static void main(String [] args){
long log = System.currentTimeMillis();
Set<String> secondarySet = new HashSet<String>(list2);
int count = 0;
for (String str : list1) {
if (secondarySet.contains(str)) {
count++;
}
}
System.out.println(System.currentTimeMillis()-log);
System.out.println(count);
}
}


Related Tutorials/Questions & Answers:
Comparing strings - Java Beginners
Comparing strings  Can anyone help with finding the number of time(s) a substring appears in a string? The code I've written can get it once...."); } } } -------------------------------------------------------------- Read for more information. http://www.roseindia.net/java
linked lists implementation - Java Beginners
linked lists implementation   1. Assume a programmer wanted to change the ADT of a list by adding the method: public boolean RemoveFirstLast (); that removes the first entry and last entry from the list
Advertisements
Java Collection
Java Collection  What is the Collection interface
Java collection
Java collection  What are differences between Enumeration, ArrayList, Hashtable and Collections and Collection
Comparing two Dates in Java with the use of before method
Comparing two Dates in Java with the use of before method... of comparing dates you have seen how to use after() method in java class for comparing... with the use of java.util.Date class. For comparing date we are using before() method
Collection in java
Collection in java  What are the meaning of the letters E,T,K and V that come in the collection concept
Java collection
Java collection  What is relation between map and set
Java Collection
Java Collection  What are Vector, Hashtable, LinkedList and Enumeration
Java collection
Java collection  What are differences between Enumeration, ArrayList, Hashtable and Collections
java collection
java collection  how do I use a treeset to print unique words
Comparing two Dates in Java
Comparing two Dates in Java   ... using java.util.Date class. For comparing dates, we will be using compareTo() method. The compareTo() method returns integer value after comparing the dates
lists
lists  how to implement lists by using array
Collection classes in java
is the reason using java collection classes saved/stored the data/content.I don't understand, what is the idea using java collection classes in project. Or the data is stored in both database and java collection classes
Collection classes in java
is the reason using java collection classes saved/stored the data/content.I don't understand, what is the idea using java collection classes in project. Or the data is stored in both database and java collection classes
Java garbage collection
Java garbage collection  What is Garbage Collection and how to call it explicitly
Java Collection API - Java Tutorials
Java Collection API Collection was added to Java with J2SE 1.2 release. Collection framework is provided in 'java.util.package'. All collections... of the collection interfaces. Also, they are reusable data structures. Algorithms
garbage collection - Java Beginners
of memory.It identifies the objects that are no longer used by a program. A Java object is subject to garbage collection when it becomes unreachable to the program... It is controlled by the JVM , The JVM runs periodically by using "mark" and "sweep
Java collection-LinkedList
Java collection-LinkedList  How to use java collection-linked list... implemented List by its subclass LinkedList. Using the add() method, we have... by using the method remove(). The iterator method then iterates through
Java collection -Hashtable
Java collection -Hashtable   What is Hashtable in java collection?   Java collection -Hashtable;- The hashtable is used to store value... it. Here Map is implemented by its subclass Hashtable. Using the put method, we have
Java collection LinkedHashSet
Java collection LinkedHashSet  How can we use LinkedHashSet in java collection?   import java.util.Iterator; import... elements are duplicate or not Then we have removed an element ??R?? using remove
Java Collection-TreeSet
Java Collection-TreeSet  What is TreeSet in Java Collection?  ... the elements of treeset using Iterator and display the elements.   Example... of treeset using Iterator and display the elements
Java collection Vector
Java collection Vector  How can we use the vector class in java... an element ??89?? using remove() method from the Vector and iterated the remaining elements of vector using Iterator and display them
Java collection Stack example
Java collection Stack example  How to use Stack class in java collection?   The Stack class uses the First In Last Out(FILO) mechanism... collection. We are using three methods of Stack. push(object items): The push
Collection Framework - Java Beginners
Collection Framework  Pls explain the disadvantages of using collection framework as it was written in this forum ? It must cast to correct type. ? Cannot do compile time checking. I couldnot get in detail as to what
java collection - Java Beginners
java collection  want a java program using collections for an algorithm the algorithm is give below algorithm has some transactions T1=ABCE T2=CDE T3=DE T4=CDEG T5=BG T6=AE T7=BCG T8=C T9=A now compare T9
Java collection Queue Example
Java collection Queue Example  How can we use Queue in java collection?   import java.util.LinkedList; import java.util.Queue; public... LinkedList(); queue.add("Java"); queue.add("DotNet
garbage collection implementation dependent java
garbage collection implementation dependent java  How a garbage collection works in Java
Java collection HashSet
Java collection HashSet  How can we use HashSet in java program?   The hashSet class is used to create a collection and store it in a hash table. Each collection refer to a unique value. import java.util.Collections
Java HashSet Collection problem
Java HashSet Collection problem  Here's how the HashSet works...-initialize p using p= new Prac() after the first insertion then only once the insertion...;Prac>(); So, while adding the object of Prac using add method of hashset, it get
Java collection HashSet and TreeSet
Java collection HashSet and TreeSet   How can we used HashSet... two subclasses HashSet and TreeSet. Now using the add() method, we have added... from the HashSet by using the method remove(). Now we have created another
Java garbage collection
Java garbage collection  Can an unreachable object become reachable again
Advertisements
 

 

 

DMCA.com