Home > Java > javaTutorial > body text

Java Example - Get the largest element of a vector

黄舟
Release: 2017-02-04 10:02:42
Original
1512 people have browsed it

The following example demonstrates using the v.add() method of the Vector class and Collections.max() of the Collection class to obtain the maximum element of the vector:

/*
 author by w3cschool.cc
 Main.java
 */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("最大元素是:"+obj);
   }}
Copy after login

The output result of the above code is:

最大元素是:3.4324
Copy after login

The above is a Java example - getting the content of the largest element of a vector. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!