Java中的Ints max()函数
max()Ints类的方法返回数组中存在的最大值。以下是语法-
static int max(int... array)
我们首先来看一个例子-
示例
import com.google.common.primitives.Ints;
class Demo {
public static void main(String[] args) {
int[] myArr = { 10, 20, 30, 40, 50, 60,20, 80, 20, 100 };
System.out.println(Ints.join("-", myArr));
System.out.println("Maximum value from the array = " + Ints.max(myArr));
//查找元素20的最后一个索引
int index = Ints.lastIndexOf(myArr, 20);
if (index != -1) {
System.out.println("The last index of element 20 = " + index);
} else {
System.out.println("元素20不在数组中。");
}
}
}输出结果
Maximum value from the array = 100 10-20-30-40-50-60-20-80-20-100 The last index of element 20 = 8
热门推荐
10 香港老妈结婚祝福语简短
11 毕业立体贺卡祝福语简短
12 简短新年年会祝福语
13 评论小品祝福语大全简短
14 恭喜师兄结婚祝福语简短
15 员工集体辞职祝福语简短
16 高中新生祝福语 简短
17 装修祝福语男生搞笑简短
18 生日开业蛋糕祝福语简短