Loading, please wait...

Monday, March 23, 2009

突然想到字符串与整数相乘的简单实现

用正则,效率还算不错。
public class StringUtility { 
   public static String buildString(String cell, int length) {
        StringBuilder ret = new StringBuilder(length);
        ret.setLength(length);
        ret.setCharAt(length - 1, ' ');
        return ret.toString().replaceAll(".", cell);
    }

    public static void main(String[] args) {
        System.out.println(StringUtility.buildString("[]", 10000));
    } 
} 

不知道还有没有更好的实现方法。

转载声明: 出自: Ghoul To World!作者: GreatGhoul

2 comments:

Note: Only a member of this blog may post a comment.