0

I am trying to run an old project in Java using IntelliJ. The ReadMe file says to use jdk 1.3 or higher. I tried jdk 1.4.2 and got some errors:

If I use jdk 1.3 I get an error for only String[] t = words.split("_"); function because of missing split. I want to know which is the oldest version of the jdk that contains split function.

How can I find that?

Ahmad
  • 8,811
  • 11
  • 76
  • 141
  • The Javadoc tells you when a class or method was added. If the method doesn't say, look at the class. The latest version of IntelliJ will warn you if you try to use a never method/class than your target version. – Peter Lawrey Jul 23 '16 at 14:01

2 Answers2

1

You are right. When developing you should first prevent the runtime version target and take a look at the JavaDoc

String#split is available since java 4

You can for sure always check the Java version at runtime by doing this:

System.out.println(System.getProperty("java.version"));
SpaceCore186
  • 586
  • 1
  • 8
  • 22
ΦXocę 웃 Пepeúpa ツ
  • 47,427
  • 17
  • 69
  • 97
1

You have specifically asked about JDK 1.3 version.You can use StringTokenizer to break a string into tokens.

 StringTokenizer st = new StringTokenizer("this is a test");
 while (st.hasMoreTokens()) {
     System.out.println(st.nextToken());
 }

Note:

StringTokenizer is a legacy class that is retained for compatibility reasons although its use is discouraged in new code. It is recommended that anyone seeking this functionality use the split method of String or the java.util.regex package instead.

Unknown
  • 2,037
  • 3
  • 30
  • 47
  • Thanks, however I need the code for `String[] t = words.split("_");`, How can I achieve it in 3.1 – Ahmad Jul 23 '16 at 14:12
  • Sorry, I think I mixed two questions with each other, I created another question http://stackoverflow.com/questions/38542768/java-split-in-jdk-1-3 for the second part, you may want to move your answer there – Ahmad Jul 23 '16 at 14:22