hide several numbers of account, 123402010000201 ---> 12340********201 - Android java.lang

Android examples for java.lang:String Algorithm

Description

hide several numbers of account, 123402010000201 ---> 12340********201

Demo Code

import android.annotation.SuppressLint;
import java.text.SimpleDateFormat;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main{

    /**//from  w  w  w.j av  a2 s.  co m
     * hide several numbers of account, 
     * example: 123402010000201 --->  12340********201
     * 
     * @param phone
     * @return
     */
    public static String hiddenSevralNum(final String str) {
        char[] number = str.toCharArray();
        int len = number.length;
        for (int i = 3; i < len - 4; i++) {
            number[i] = '*';
        }
        return String.valueOf(number);
    }

}

Related Tutorials