我正在测试如何打印数组。我可以使用for loop
进行打印,但是当我尝试使用Arrays.toString
或Arrays.deepToString
时却无法正常工作。这是一个例子
package Week4;
import java.util.Arrays;
public class prac2 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String[][] array = new String[][] {
{ "Elem11", "Elem12", "Elem13" },
{ "Elem21", "Elem22", "Elem23" },
{ "Elem31", "Elwm32", "Elem33" } };
System.out.println(Arrays.deepToString(array));
}
}
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
Arrays cannot be resolved
at Week4.prac2.main(prac2.java:14)
我正在使用JRE1.8.0_20。这与图书馆有关吗?我正在使用eclipse。
答案 0 :(得分:1)
我认为您使用的是IDE,它没有正确安装或不完整的软件包。
1. i ran your code in my IDE
2. import java.util.Arrays;
3. since you still have error i press `ctrl` then hover to `import java.util.Arrays;` which leads me to the `Arrays.class`
4. look to the hierarchy of the packages and looked where it came from `rt.jar` which contains all of the compiled class files for the base Java Runtime environment.