我正在复习一份即将完成的测试的学习指南,并决定进入DrJava,尝试用String
解决一些问题。它曾经运行得很好,但现在我不断收到错误"The constructor String(java.lang.String) is undefined
,无法继续编写代码。我查过写字符串的不同方法,但都不起作用。知道我做错了什么吗?谢谢
public class StudyGuide {
public static void main(String args[]) {
String str = new String("Write a method that replicates toCharArray");
System.out.println("The string says:");
}
}
不要使用构造函数来生成String对象。相反,使用这个:
String str= "Write a method that replicates toCharArray";
然后你的程序会看起来像这样:
public class StudyGuide {
public static void main(String args[]) {
String str = new String("Write a method that replicates toCharArray");
System.out.println("The string says: "+str);
}
}