String realname = "程序员";
String mobile = "15888888888";
String realname1 =null;
char[] r = realname.toCharArray();
char[] m = mobile.toCharArray();
if(r.length ==1){
realname1 = realname;
}
if(r.length == 2){
realname1 = realname.replaceFirst(realname.substring(1),"*");
}
if (r.length > 2) {
realname1 = realname.replaceFirst(realname.substring(1,r.length-1) ,"*");
}
for(int i=0; i<m.length;i++){
if(i>2 && i<7){
m[i] = '*';
}
}
String mobile1 = String.valueOf(m);
System.out.println(realname1);//程*员
System.out.println(mobile1);//158****8888
java后台姓名与手机号中间用*号代替
最新推荐文章于 2024-07-26 03:15:38 发布