How to Get Max Element in a Vector in Java


In this example, we will learn 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:

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments