Author
String replaceAll function error
Michael L. Zhang
Ranch Hand
Joined: Jul 06, 2003
Posts: 33
I have a small test program, but when I compile it I got an error. Can someone tell me why I got compliling error? javac TestReplace.java TestReplace.java:8: cannot resolve symbol symbol : method replaceAll (java.lang.String ,java.lang.String ) location: class java.lang.String String xyz = str.replaceAll("a","b"); ^ 1 error
Michael Dunn
Ranch Hand
Joined: Jun 09, 2003
Posts: 4632
posted Jan 06, 2006 11:38:00
0
are you using a version of jave earlier than 1.4? also, when you do get it to compile, it won't run - main() is wrong
Michael L. Zhang
Ranch Hand
Joined: Jul 06, 2003
Posts: 33
My java version "1.3.1_14" The issue with main(), You mean I should use public static void main(String{} args), right?
marc weber
Sheriff
Joined: Aug 31, 2004
Posts: 11343
Originally posted by Michael L. Zhang: ... The issue with main(), You mean I should use public static void main(String{} args), right?
public static void main(String[] args)
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
jiju ka
Ranch Hand
Joined: Oct 12, 2004
Posts: 302
public static void main(String[] args) is the right one. But that is not your compilation issue. Your compilation issue is not in code. The Issue is String.replaceAll method is not in your java library. See the documentation for 1.3 http://java.sun.com/j2se/1.3/docs/api/java/lang/String.html replaceAll(String, String) is not defined but in jdk 1.4 and 1.5 it is present [ January 06, 2006: Message edited by: jiju ka ]
Michael L. Zhang
Ranch Hand
Joined: Jul 06, 2003
Posts: 33
Thanks every one! I just joined the new company, and I assumed my java version is 1.4 or later, but it turned out it is not the case. Will talk to company admin to upgrade the java.
Paul Clapham
Bartender
Joined: Oct 14, 2005
Posts: 16483
Or if your company is not upgrading yet for some reason, then you could use the char versionwhich does exist in Java 1.3. Note that you can only replace one char by another with this method, nothing more complex than that.
subject: String replaceAll function error