我可以问为什么以下输出为假?
import java.util.Arrays;
public class Test2 {
public static void main(String[] args) {
new Test2();
}
private final int[] VOWEL_POS = {0,4,8,14,20};
Test2(){
if(Arrays.asList(VOWEL_POS).contains(0)){
System.out.print("TRUE");
}else{
System.out.print("FALSE");
}
}
}
Run Code Online (Sandbox Code Playgroud)
谢谢!
asList这里的方法返回一个List<int[]>,这不是你所期望的.
原因是你不能拥有List<int>.为了实现你想要的,做一个Integer- 的数组Integer[].
Apache commons-lang就是ArrayUtils这样的:
if(Arrays.asList(ArrayUtils.toObject(VOWEL_POS)).contains(0))
Run Code Online (Sandbox Code Playgroud)
或者最初制作数组,Integer[]以便不需要转换