Find maximum
element of Java Array List
import java.util.ArrayList;
import java.util.Collections;
public class FindMaximumOfArrayListExample
{
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.max(arrayList);
System.out.println("Maximum Element of
Java ArrayList is : " + obj);
}
}
Find maximum
element of Java Hash Set
import java.util.HashSet;
import
java.util.Collections;
public class
FindMaximumOfHashSetExample
{
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.max(hashSet);
System.out.println("Maximum Element of Java HashSet is :
" + obj);
}
}
Find maximum
element of Java Vector
import java.util.Vector;
import
java.util.Collections;
public class
FindMaximumOfVectorExample
{
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.max(v);
System.out.println("Maximum
Element of Java Vector is : " + obj);
}
}
Get Enumeration
over Java Array List
import
java.util.Enumeration;
import
java.util.ArrayList;
import java.util.Collections;
public class
GetEnumerationOverArrayListExample
{
public static void
main(String[] args)
{
ArrayList arrayList =
new ArrayList();
arrayList.add("A");
arrayList.add("B");
arrayList.add("D");
arrayList.add("E");
arrayList.add("F");
Enumeration e =
Collections.enumeration(arrayList);
System.out.println("Enumerating
through Java ArrayList");
while(e.hasMoreElements())
System.out.println(e.nextElement());
}
}
Get Enumeration
over Java Hash Set
import
java.util.Enumeration;
import java.util.HashSet;
import
java.util.Collections;
public class
GetEnumerationOverHashSetExample
{
public static void
main(String[] args)
{
HashSet hashSet = new
HashSet();
hashSet.add("A");
hashSet.add("B");
hashSet.add("D");
hashSet.add("E");
hashSet.add("F");
Enumeration e =
Collections.enumeration(hashSet);
System.out.println("Enumerating
through Java HashSet");
while(e.hasMoreElements())
System.out.println(e.nextElement());
}
}
Get Enumeration
over Java Vector
import
java.util.Enumeration;
import java.util.Vector;
import
java.util.Collections;
public class
GetEnumerationOverVectorExample
{
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");
Enumeration e =
Collections.enumeration(v);
System.out.println("Enumerating
through Java Vector");
while(e.hasMoreElements())
System.out.println(e.nextElement());
}
}