The method format(String, Object[]) is undefined for the type String

I have this error:

The method format(String, Object[]) is undefined for the type String.

What does mean that?

import java.io.*;

import java.util.*;

public class Main {

public static void main(String[] args) {

String [] test =null;

String str1="Today";

String str2="is";

String str3="monday";

String str4="good";

String format = "%1$-9s%2$-3s";

format +="%3$-30s%4$-30s\n";

test = new String[] {str1, str2, str3,str4};

File f = new File("D:\\temp\\test.txt");

try

{

if ( f.exists() )

{

PrintStream ps = new PrintStream(new FileOutputStream("D:\\temp\\test.txt"));

ps.println(String.format(format,(Object[])test));

ps.flush();

ps.close();

}

else

{

PrintStream ps = new PrintStream(new FileOutputStream("D:\\temp\\test.txt"));

ps.println(String.format(format,(Object[])test));

ps.flush();

ps.close();

}

}

catch (Exception e)

{

System.out.println(e);

}

}

}

[1092 byte] By [warapa] at [2007-11-27 8:48:24]
# 1
What version of Java are you using?
floundera at 2007-7-12 20:55:19 > top of Java-index,Java Essentials,New To Java...
# 2
1.4.2
warapa at 2007-7-12 20:55:19 > top of Java-index,Java Essentials,New To Java...
# 3
is it related to java version?Message was edited by: warap
warapa at 2007-7-12 20:55:19 > top of Java-index,Java Essentials,New To Java...
# 4
Yes, that method is available in 1.5. Either upgrade or choose another way to do what you want.
floundera at 2007-7-12 20:55:19 > top of Java-index,Java Essentials,New To Java...
# 5
what is the another way based on my code story?
warapa at 2007-7-12 20:55:19 > top of Java-index,Java Essentials,New To Java...
# 6
I don't know. It's your code, not mine. Your job, not mine.Try writing your own method that adds the values into a StringBuilder or StringBuffer in the required format.
floundera at 2007-7-12 20:55:19 > top of Java-index,Java Essentials,New To Java...
# 7
it works with version 1.5um..ok...will try another way...
warapa at 2007-7-12 20:55:19 > top of Java-index,Java Essentials,New To Java...