Java 中的 Ints 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]
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP