hide several characters of email - Android java.lang

Android examples for java.lang:Character

Description

hide several characters of email

Demo Code

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

public class Main{

    /**/*from  ww  w .ja  v  a  2  s  . co  m*/
     * hide several characters of email
     * example: 13849620635@example.com --->  126********@example.com
     * @param email
     * @return
     */
    public static String hiddenEmail(final String str) {
        char[] email = str.toCharArray();
        int len = email.length;
        for (int i = 3; i < len; i++) {
            if (email[i] == '@') {
                break;
            }
            email[i] = '*';
        }
        return String.valueOf(email);
    }

}

Related Tutorials