【Java/字符串处理】SpringUtils提供的重复字符串、固定长度左补右补空格的三函数

【SpringUtils的依赖】

        <dependency>
            <groupId>commons-lang</groupId>
            <artifactId>commons-lang</artifactId>
            <version>2.6</version>
        </dependency>

【代码】

package com.lab;

import org.apache.commons.lang.StringUtils;

public class StringUtilsUsage {
    public static void main(String[] args){
        String str1=StringUtils.repeat("*",10);
        System.out.println("重复字符串1="+str1);

        String str2=StringUtils.repeat("Abc","_",10);
        System.out.println("重复字符串2="+str2);

        String str3=StringUtils.leftPad("abc",10);
        System.out.println("固定长度,左补空格="+str3);

        String str4=StringUtils.rightPad("abc",10);
        System.out.println("固定长度,右补空格="+str4);
    }
}

【输出】

重复字符串1=**********
重复字符串2=Abc_Abc_Abc_Abc_Abc_Abc_Abc_Abc_Abc_Abc
固定长度,左补空格=       abc
固定长度,右补空格=abc       

END

posted @ 2022-03-13 05:02  逆火狂飙  阅读(580)  评论(0)    收藏  举报
生当作人杰 死亦为鬼雄 至今思项羽 不肯过江东