package com.keeya.util;public class MyOwnerPrint {
public static void print(String format, Object... objects ) {
int index = 0;
int max = objects.length;
try{
while (index < max){
format = format.replaceFirst("\\{" + index +"\\}", objects[index++].toString());
}
System.out.print(format);
}catch (Exception e) {
e.printStackTrace();
}
}
public static void println(String format, Object... objects ){
print(format, objects );
System.out.println();
}
}
public class Test {
public static void main(String[] args) {
MyOwnerPrint.print("this is a test {0} , hello world : {1} : {2} {3} {4} ","fd","sc",3*4);
}
}
测试结果:
this is a test fd , hello world : sc : 12 {3} {4} 目前没有解决如: format里的 {0} 这个如果输入是{   0  }等类似格式后就无法正常输出。
希望大家给点意见。