Example to find maxmimum element in a Vector
Example to find maximum element in a Vector
This java example shows how to find a maximum element of Java Vector using max method of Collections class.To find maximum element of Java Vector use, static Object max(Collection c) method of Collections class.
This method returns the maximum element of Java Vector according to its natural ordering.
The Output is:
Reference Books:
This java example shows how to find a maximum element of Java Vector using max method of Collections class.To find maximum element of Java Vector use, static Object max(Collection c) method of Collections class.
This method returns the maximum element of Java Vector according to its natural ordering.
import java.util.Vector; import java.util.Collections; public class FindMaximumOfVectorExample { public static void main(String[] args) { //create a Vector object Vector v = new Vector(); //Add elements to 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); } }
The Output is:
Maximum Element of Java Vector is : 357.349
Reference Books: