String类型中的方法格式(String,Object [])不适用于参数(...)

Bar*_*ble 13 java string format

这是我的代码:

int hoursFormat = 1, minsFormat = 2, secsFormat = 3;
String timeFormat = String.format("%02d:%02d:%02d",hoursFormat, minsFormat, secsFormat);
Run Code Online (Sandbox Code Playgroud)

这给出了编译错误:

Unresolved compilation problem: 
    The method format(String, Object[]) in the type String is not applicable for the 
      arguments (String, int, int, int)
Run Code Online (Sandbox Code Playgroud)

为什么我在这里收到此错误,如何解决?

yan*_*ike 15

我有一个类似printf的问题.我使用的是JDK 1.6.0_27.将合规性级别设置为1.6解决了我的问题.这可以通过以下方式设置.

项目>属性> Java编译器

您还可以参考以下主题:

为什么我用简单的printf得到编译错误?


ada*_*ost 0

您拥有jdk 1.4或低于版本。String.format() 方法在 中介绍Jdk 1.5

看看coderanch帖子。