In this example we will show the method to get the max element in a Vector in Java.
Source Code
package com.beginner.examples;
import java.util.Vector;
import java.util.Collections;
public class MaxElementOfVector {
public static void main(String[] args) {
Vector vectors = new Vector();
vectors.add(6);
vectors.add(1);
vectors.add(4);
System.out.println("Max : " + Collections.max(vectors)); // get the max element
}
}
Output:
Max : 6
References
Imported packages in Java documentation: