Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3785570
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T11:32:55+00:00 2026-05-19T11:32:55+00:00

You have user.nick@domain.com and result should be: ******@domain.com Currently I’m doing it this way:

  • 0

You have

user.nick@domain.com

and result should be:

******@domain.com

Currently I’m doing it this way:

public static String removeUserFromEmail(String email) {
    StringBuffer sbEmail = new StringBuffer(email);
    int start = sbEmail.indexOf("@");
    sbEmail.delete(0, start);
    return "******" + sbEmail.toString();
}

Is there something simpler or more elegant?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T11:32:56+00:00Added an answer on May 19, 2026 at 11:32 am

    Nothing wrong with that solution, although I have two suggestions:

    1) Use StringBuilder instead of StringBuffer unless you need to synchronize access between multiple threads. There is a performance penalty associated with StringBuffer that for this application is likely unnecessary.

    2) One of the benefits of StringBuilder/Buffer is avoiding excessive string concatenations.

    Your return line converts the Buffer to a string, and then concatenates. I would probably do this instead:

    int start = email.indexOf("@");
    
    if (start < 0) {
        return "";  // pick your poison for the error condition
    }
    
    StringBuilder sbEmail = new StringBuilder(email);
    sbEmail.replace(0, start, "******");
    return sbEmail.toString();
    

    FYI – my solution is really just some thoughts on your current use of StringBuffer (which are hopefully helpful). I would recommend Konstantin’s solution for this simple string exercise. Simple, readable, and it gives you the opportunity to handle the error condition.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm doing a game. I have a list of users (nicks): List<string> users; This
Following scenario: I have user object: ... @Column(name = TITLE) private String title; @NotNull
I have user submitted tags that can be any type of (valid) UTF-8 string.
I have a class representing a user called Nick and I want to use
I have the following two classes: import java.io.*; import java.util.*; public class User {
I have user and user_role tables. The user_role table has two columns: user_id role_name
I have User and Client, both of which have one Address. I want to
I have user control named DateTimeUC which has two textboxes on its markup: <asp:TextBox
I have user control in my MVC2 app placed in the Content folder (it's
I have user generated podcasts, each with their own RSS feed. Is there a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.