Im going over a study guide for a test that I have soon and decided to go into DrJava and try to figure something with String
out. It worked fine once but now I keep getting the error "The constructor String(java.lang.String) is undefined
and cant continue writing my code. I've looked up the different ways to write a string and none are working. Any idea what I'm doing wrong? Thanks!
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:");
}
}
Don't use the constructor for making String objects. Instead, use this:
String str= "Write a method that replicates toCharArray";
Then your program would look something like this:
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);
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.