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