在App Engine文档中,JID...此方法签名中的省略号()是什么?
public MessageBuilder withRecipientJids(JID... recipientJids)
Run Code Online (Sandbox Code Playgroud)
这三个点的功能是什么?
我想知道如何在Java中连接4个字符串数组.
有一个问题已经存在. 如何在Java中连接两个数组?
但我试图复制它,但它对我不起作用.
这就是我的代码:
调用方法:
concatAll(jobs1, jobs2, jobs3, jobs4);
Run Code Online (Sandbox Code Playgroud)
方法本身:
public String[] concatAll(String[] jobsA, String[] jobsB, String[] jobsC, String[] jobsD) {
int totalLength = jobsA.length;
for (String[] array : jobsD) {
totalLength += array.length;
}
String[] result = Arrays.copyOf(jobsA, totalLength);
int offset = jobsA.length;
for (String[] array : jobsD) {
System.arraycopy(array, 0, result, offset, array.length);
offset += array.length;
}
return result;
}
Run Code Online (Sandbox Code Playgroud) 调用需要String或int输入的方法没有问题.例如:
return stringMethod("Hello World");
return intMethod(1,2,3);
Run Code Online (Sandbox Code Playgroud)
但是在调用需要输入的int数组的方法时,我遇到了语法问题.我用来在下面的代码中调用方法countEvens的语法不起作用.
public class _01_countEvens{
public static void main(String[] args){
return countEvens({2,4,6,7});
}
}
public int countEvens(int[] nums){
int result = 0;
for(int x = 0; x < nums.length; x++){
if(nums[x] % 2 == 0) result++;
}
return result;
}
}
Run Code Online (Sandbox Code Playgroud)
