Java中的int concat()函数
Ints类中的concat()函数用于连接作为参数传递的数组。语法如下-
public static int[] concat(int[]... arr)
此处,参数arr为零或多个整数数组。
让我们看一个例子-
示例
import com.google.common.primitives.Ints;
import java.util.*;
class Demo {
public static void main(String[] args) {
int[] myArr1 = { 100, 150, 230, 300, 400 };
int[] myArr2 = { 450, 550, 700, 800, 1000 };
System.out.println("Array 1 = ");
for(int i=0; i < myArr1.length; i++) {
System.out.println(myArr1[i]);
}
System.out.println("Array 2 = ");
for(int i=0; i < myArr2.length; i++) {
System.out.println(myArr2[i]);
}
int[] arr = Ints.concat(myArr1, myArr2);
System.out.println("Concatenated arrays = "+Arrays.toString(arr));
}
}输出结果
Array 1 = 100 150 230 300 400 Array 2 = 450 550 700 800 1000 Concatenated arrays = [100, 150, 230, 300, 400, 450, 550, 700, 800, 1000]
热门推荐
10 儿子立冬祝福语简短独特
11 对当兵的祝福语简短
12 侄儿高考试祝福语简短
13 伴郎红包祝福语朋友简短
14 媳妇生日简短祝福语朋友
15 公司年会祝福语简短最好
16 元旦感恩祝福语简短大全
17 红包祝福语简短10字
18 周六早晨祝福语简短