Create Java Array List From
Enumeration
import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
import java.util.Vector;
public class CreateArrayListFromEnumerationExample
{
public static void main(String[] args)
{
vector v = new Vector();
v.add("A");
v.add("B");
v.add("D");
v.add("E");
v.add("F");
System.out.println("Vector contains :
" + v);
Enumeration e = v.elements();
ArrayList aList = Collections.list(e);
System.out.println("Arraylist contains :
" + aList);
}
}
Create List containing n Copies of
Specified Object
import java.util.Collections;
import java.util.List;
import java.util.Iterator;
public class CreateListOfNCopiesExample
{
public static void main(String[] args)
{
List list =
Collections.nCopies(5,"A");
System.out.println("List contains,
");
Iterator itr = list.iterator();
while(itr.hasNext())
System.out.println(itr.next());
}
}
Find Minimum element of Java Array
List
import java.util.ArrayList;
import java.util.Collections;
public class FindMinimumOfArrayListExample
{
public static void main(String[] args)
{
ArrayList arrayList = new ArrayList();
arrayList.add(new
Integer("327482"));
arrayList.add(new Integer("13408"));
arrayList.add(new
Integer("802348"));
arrayList.add(new
Integer("345308"));
arrayList.add(new
Integer("509324"));
Object obj = Collections.min(arrayList);
System.out.println("Minimum Element of
Java ArrayList is : " + obj);
}
}
Find Minimum element of Java Hash Set
import java.util.HashSet;
import java.util.Collections;
public class FindMinimumOfHashSetExample
{
public static void main(String[] args)
{
HashSet hashSet = new HashSet();
hashSet.add(new Long("923740927"));
hashSet.add(new Long("4298748382"));
hashSet.add(new Long("2374324832"));
hashSet.add(new Long("2473483643"));
hashSet.add(new
Long("32987432984"));
Object obj = Collections.min(hashSet);
System.out.println("Minimum Element of
Java HashSet is : " + obj);
}
}
Find Minimum element of Java Vector
import java.util.Vector;
import java.util.Collections;
public class FindMinimumOfVectorExample
{
public static void main(String[] args)
{
Vector v = new Vector();
v.add(new Double("324.4324"));
v.add(new Double("345.3532"));
v.add(new Double("342.342"));
v.add(new Double("357.349"));
v.add(new Double("23.32453"));
Object obj = Collections.min(v);
System.out.println("Minimum Element of
Java Vector is : " + obj);
}
}
No comments:
Post a Comment