java后台姓名与手机号中间用*号代替

               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
                      if(i>2 && i<7){
                          m[i] = '*';
                      }
                  }
                  String mobile1 =  String.valueOf(m);
                  System.out.println(realname1);//程*员
                  System.out.println(mobile1);//158****8888

你可能感兴趣的:(java字符串解决)