adsense


Showing posts with label JAVA EXAMPLES VECTOR MAXIMUM. Show all posts
Showing posts with label JAVA EXAMPLES VECTOR MAXIMUM. Show all posts

Friday, 30 October 2015

JAVA EXAMPLES VECTOR MAXIMUM PAGE 150

COMPUTER LANGUAGES HTML,C,C++.JAVA,.NET AND MULTIMEDIA basics and programs click home button



JAVA EXAMPLES VECTOR MAXIMUM






Java Examples - Vector Maximum


Problem Description:
How to get the maximum element from a vector ?
Solution:
Following example demonstrates how to get the maximum element of a vector by using v.add() method of Vector class and Collections.max() method of Collection class.
import java.util.Collections;
import java.util.Vector;

public class Main {
   public static void main(String[] args) {
      Vector v = new Vector();
      v.add(new Double("3.4324"));
      v.add(new Double("3.3532"));
      v.add(new Double("3.342"));
      v.add(new Double("3.349"));
      v.add(new Double("2.3"));
      Object obj = Collections.max(v);
      System.out.println("The max element is:"+obj);
   }
}
Result:
The above code sample will produce the following result.
The max element is: 3.4324