姓名脱敏工具类
作者:互联网
import org.apache.commons.lang3.StringUtils; /** * @Author ** * @Date 2021/10/5 * @Description: */ public class DesensitizeUtil { /** * 姓名脱敏 * @param str * @param index * @return */ public static String left(String str,int index) { if (StringUtils.isBlank(str)) { return ""; } String name = StringUtils.left(str, index); return StringUtils.rightPad(name, StringUtils.length(str), "*"); } }
测试:
public class Demo01 { public static void main(String[] args) { String name = "欧阳娜娜"; String newName = DesensitizeUtil.left(name, 2); System.out.println(newName); } }
结果:欧阳**
标签:index,姓名,name,public,str,工具,StringUtils,脱敏,String 来源: https://www.cnblogs.com/nastu/p/15514339.html