Java 中的 Ints join() 函数
Ints 类的 join() 方法返回一个包含以分隔符分隔的指定 int 值的字符串。语法如下:-
public static String join(String separator, int[] arr)
其中,分隔符参数应显示在连续值之间,而 arr 是一个 int 值数组。
让我们先看一个示例:
示例
import com.google.common.primitives.Ints;
class Demo {
public static void main(String[] args) {
int[] myArr = { 10, 20, 30, 40, 50, 60,70, 80, 90, 100 };
System.out.println(Ints.join("-", myArr));
int index = Ints.indexOf(myArr, 40);
if (index != -1) {
System.out.println("Element 40 is in the array at position " + (index+1));
} else {
System.out.println("Element 40 is not in the array");
}
}
}输出
10-20-30-40-50-60-70-80-90-100 Element 40 is in the array at position 4
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP