Cannot find symbol
Symbol: method substring(int)
location: class java.lang.StringBuilder
Run Time error msg:
Exceptiom in thread "main" javaa.lang.RuntimeException: Uncompilable source code at testb.Main.main (Main.java:17) Java Result:1
Source code:
public class Main {Data type of s1 is StringBuilder, problem I face is an Compatible problem, there is substring method in 1.5 and later version but in StringBuilder but not in 1.5.
public static void main(String[] args) {
StringBuilder s1 = new StringBuilder("Java");
String s2 = "Love";
s1.append(s2);
s1.substring(4);
}
}
So what you do in 1.5version below is not trying to use substring() method in StringBuilder, you can inital a String and assign content in StringBuilder to that String, and use substring() method in String(). Or you can upgrade your Java verios yo 1.5 or above.
Reference:
https://javatutorialhq.com/java/lang/stringbuilder-class-tutorial/substring-method-example/
No comments :
Post a Comment