Java tutorial
//package com.java2s; import android.text.TextUtils; public class Main { public static String getHideMobile(String mobile) { if (TextUtils.isEmpty(mobile)) { return ""; } if (mobile.length() <= 3) { return mobile; } String str = mobile.substring(0, 3); for (int i = 3; i < mobile.length(); i++) { str += "X"; } return str; } }