org.apache.commons.lang3的StringUtils

方法如下:

public static String leftPadTime(Integer time){
    return StringUtils.leftPad(String.valueOf(time), 2, "0");
}

左侧填充:
leftPad():

StringUtils.leftPad(String str,int size); 
StringUtils.leftPad(String str,int size,String padStr);

右侧填充:
rightPad():

StringUtils.rightPad(String str,int size); 
StringUtils.rightPad(String str,int size,String padStr);
中间填充:
center():

StringUtils.center(String str, int size); 
StringUtils.center(String str, int size, String padString);

例:
StringUtils.center("abcdef", 20);

返回结果(左右各7个空格):abcdef

StringUtils.center("abcdef", 20,"*_");

返回结果:*_*_*_abcdef*_*_*_*_

StringUtils.leftPad("abc", 10, "*");

返回结果:*******abc

StringUtils中常用方法leftPad(),rightPad(),center()的更多相关文章

  1. org.apache.commons.lang.StringUtils的常用方法

    org.apache.commons.lang.StringUtils是apache的commons-lang-x.x.jar下的包,里面包含很多字符串操作方法, 官网(http://commons. ...

  2. StringUtils中的常用的方法

    org.apache.commons.lang.StringUtils中常用的方法,这里主要列举String中没有,且比较有用的方法: 1. 检查字符串是否为空: static boolean isB ...

  3. org.apache.commons.lang.StringUtils中常用的方法

    org.apache.commons.lang.StringUtils中常用的方法,这里主要列举String中没有,且比较有用的方法: 1. 检查字符串是否为空: static boolean isB ...

  4. StringUtils 的常用方法

    StringUtils 方法的操作对象是 Java.lang.String 类型的对象,是 JDK 提供的 String 类型操作方法的补充,并且是 null 安全的(即如果输入参数 String 为 ...

  5. StringUtils类常用方法介绍

    StringUtils方法包的位置:org.apache.commons.lang.StringUtils StringUtils 方法的操作对象是 java.lang.String 类型的对象,是 ...

  6. 【转】 StringUtils中 isNotEmpty 和isNotBlank的区别

    [转自]http://blog.csdn.net/foamflower/article/details/5713604 isNotEmpty将空格也作为参数,isNotBlank则排除空格参数 Str ...

  7. StringUtils中 isNotEmpty 和isNotBlank的区别【java字符串判空】

    isNotEmpty(str)等价于 str != null && str.length > 0 isNotBlank(str) 等价于 str != null &&am ...

  8. StringUtils中 isEmpty 和isBlank的区别

    StringUtils方法的操作对象是java.lang.String类型的对象,是JDK提供的String类型操作方法的补充,并且是null安全的(即如果输入参数String为null则不会抛出Nu ...

  9. IT第九天 - 包、访问修饰符、变量的内存分配、String类中常用方法

    IT第九天 上午 包 1.包的命名规则:域名.项目名称.模块名 2.如:Wfei.com.windows.login 访问限制符 1.四种访问限制符分别对应为: (1)default:默认的,默认为p ...

随机推荐

  1. Maximum likelihood from incomplete data via the EM algorithm (1977)

    Maximum likelihood from incomplete data via the EM algorithm (1977)  

  2. java代码中的三元表达式

    1.格式 布尔型表达式?a:b,例子:boolean c;int a=1,b=2;c=a>b?10:15,这样子最终返回的结果是15

  3. ios怎样在一个UIImageButton的里面加一些自己定义的箭头

    能够採用例如以下方法,写一个函数: -(UIImage*) getOneImageButtonWithArrow{ //tmpView做附控件 UIView *tmpView = [[UIView a ...

  4. ABAP 通过字段找表程序

    2.获取数据保存在哪个数据表的方法: 1.前台对指定栏位 使用F1帮助找表,2.st05 跟踪业务操作过程,检索需要的数据表,(此方法找表很高效)3.对于文本字段找表,可以找到前台维护处,->维 ...

  5. Hamming校验码

    可参考:http://winda.blog.51cto.com/55153/1068000 Hamming校验码作用:用于校验通信数据,防止出现错误,并具有一定的纠错功能. 汉明码在传输的消息流中插入 ...

  6. 【Advanced Windows Phone Programming】在windows phone 8中解码mp3 和编码pcm

    转眼间不做wp开发,投身于php事业已然一年了,转身看到8.1的发布,俨然一片欣欣向荣的景象,但是开发社区却没比一年前有过多大的提高,这并不是一个好现象,遂在git上开源了之前音频处理库,希望能对社区 ...

  7. ffmpeg入门基础知识

    获取ffmpeg源代码 如果你是在Windows环境下,则可以先装SVN的一个客户端TortoiseSVN(非常好用,强烈推荐),他安装完成后会集成在右键菜单中,点Checkout菜单,在弹出的界面中 ...

  8. hdu 6053(To my boyfriend)

    -----------题目链接------------- 题目描述: 给定一个矩阵,定义\(f(A)\) 为矩阵中不同元素的个数.现在要求\(f(A)\)的期望. 解法: 首先来暴力的,复杂度大约:\ ...

  9. [HAOI 2012] 外星人

    [题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=2749 [算法] 首先 , 每次对一个数x进行操作 , 只会使该数减少一个2的因子 那 ...

  10. AtCoder Grand Contest 012 C:Tautonym Puzzle

    题目传送门:https://agc012.contest.atcoder.jp/tasks/agc012_c 题目翻译 如果一个字符串是好的,那么这个字符串的前半部分和后半部分肯定一模一样.比如\(a ...