In this example, we may learn about how to find a minimum element of Vector using min method of Collections class in Java.
Source Code
package com.beginner.examples;
import java.util.Collections;
import java.util.Vector;
public class FindMinimumOfVector {
public static void main(String[] args) {
//create a Vector.
Vector vector = new Vector();
vector.add(new Integer("1024"));
vector.add(new Integer("256"));
vector.add(new Integer("128"));
/*
To find minimum element of Java Vector use static Object min(Collection c) method of Collections.
*/
Integer result = Collections.min(vector);
System.out.println("The minimum element is " + result);
}
}
Output:
The minimum element is 128
References
Imported packages in Java documentation: