Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

public class Main {

    public static String hideEmail(String mail) {
        StringBuilder stringBuilder = new StringBuilder();
        if (mail.lastIndexOf("@") > 0) {
            int index = mail.lastIndexOf("@");
            if (index == 1) {
                stringBuilder.append(mail.substring(0, 1));
                stringBuilder.append("***");
                stringBuilder.append(mail.substring(index));
            } else {
                stringBuilder.append(mail.substring(0, 1));
                stringBuilder.append("***");
                stringBuilder.append(mail.substring(index - 1));
            }
        } else {
            return mail;
        }
        String mailHidden = stringBuilder.toString();
        if (mailHidden.length() > 20) {
            return mailHidden.substring(0, 20) + "...";
        } else {
            return mailHidden;
        }
    }
}