教程 > guava 教程 > 阅读:11

guava doubles 类——迹忆客-ag捕鱼王app官网

返回 guava primitive 实用程序


doubles 是原始类型 double 的实用程序类。


类声明

以下是 com.google.common.primitives.doubles 类的声明

@gwtcompatible(emulated = true)
   public final class doubles
      extends object

字段

序号 字段 说明
1 static int bytes 表示原始双精度值所需的字节数。

类方法

序号 方法 说明
1 static list aslist(double... backingarray) 返回由指定数组支持的固定大小列表,类似于 arrays.aslist(object[])。
2 static int compare(double a, double b) 比较两个指定的双精度值。
3 static double[] concat(double[]... arrays) 将每个提供的数组中的值返回到一个数组中。
4 static boolean contains(double[] array, double target) 如果 target 作为元素出现在数组中的任何位置,则返回 true。
5 static double[] ensurecapacity(double[] array, int minlength, int padding) 返回一个包含与数组相同值的数组,但保证具有指定的最小长度。
6 static int hashcode(double value) 返回值的哈希码; 等于调用 ((double) value).hashcode() 的结果。
7 static int indexof(double[] array, double target) 返回值 target 在数组中第一次出现的索引。
8 static int indexof(double[] array, double[] target) 返回指定目标在数组中第一次出现的起始位置,如果不存在则返回 -1。
9 static boolean isfinite(double value) 如果 value 表示实数,则返回 true。
10 static string join(string separator, double... array) 返回包含提供的双精度值的字符串,转换为由 double.tostring(double) 指定的字符串,并由分隔符分隔。
11 static int lastindexof(double[] array, double target) 返回值 target 在数组中最后一次出现的索引。
12 static comparator lexicographicalcomparator() 返回一个比较器,该比较器按字典顺序比较两个双精度数组。
13 static double max(double... array) 返回数组中存在的最大值,使用与 math.max(double, double) 相同的比较规则。
14 static double min(double... array) 返回数组中存在的最小值,使用与 math.min(double, double) 相同的比较规则。
15 static converter stringconverter() 返回一个可序列化的转换器对象,该对象使用 double.valueof(java.lang.string)double.tostring() 在字符串和双精度数之间进行转换。
16 static double[] toarray(collection collection) 返回包含集合的每个值的数组,以 number.doublevalue() 的方式转换为双精度值。
17 static double tryparse(string string) 将指定的字符串解析为双精度浮点值。

方法继承

该类继承了以下类的方法 -

  • java.lang.object

doubles 类示例

c:/> guava 中使用我们选择的任何编辑器创建以下 java 程序。

guavatester.java

import java.util.list;
import com.google.common.primitives.doubles;
public class guavatester {
   public static void main(string args[]) {
      guavatester tester = new guavatester();
      tester.testdoubles();
   }
   private void testdoubles() {
      double[] doublearray = {1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0};
      //将基元数组转换为对象数组
      list objectarray = doubles.aslist(doublearray);
      system.out.println(objectarray.tostring());
      //将对象数组转换为基元数组
      doublearray = doubles.toarray(objectarray);
      system.out.print("[ ");
      
      for(int i = 0; i< doublearray.length ; i  ) {
         system.out.print(doublearray[i]   " ");
      }
      
      system.out.println("]");
      
      //检查元素是否存在于基元列表中
      system.out.println("5.0 is in list? "   doubles.contains(doublearray, 5.0f));
      //返回元素的索引
      system.out.println("5.0 position in list "   doubles.indexof(doublearray, 5.0f));
      //返回最小值
      system.out.println("min: "   doubles.min(doublearray));
      //返回最大值
      system.out.println("max: "   doubles.max(doublearray));    
   }
}

验证结果

使用 javac 编译器编译类,如下所示

c:\guava>javac guavatester.java

现在运行 guavatester 以查看结果。

c:\guava>java guavatester

结果如下

[1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0]
[ 1.0 2.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0 ]
5.0 is in list? true
5.0 position in list 4
min: 1.0
max: 9.0

返回 guava primitive 实用程序

查看笔记

扫码一下
查看教程更方便
网站地图