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 3793366
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T12:45:53+00:00 2026-05-19T12:45:53+00:00

Is there a good class that can count the occurrences of specific strings in

  • 0

Is there a good class that can count the occurrences of specific strings in java? I’d like to keep a list of names and then create unique email addresses for each name. For each occurrence of a last name, I’d like to increment the associated number by one.

Ex: If I have 3 people with the last name Smith, I’d like their address to be smith1@(Address), smith2@(Address), and smith3@(Address). I saw a class “Map” but I can’t seem to initialize it correctly. Is there a class that I can use to keep a list of strings and their occurrences?

  • 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-19T12:45:54+00:00Added an answer on May 19, 2026 at 12:45 pm

    Map would be a viable data structure for this, if you’re just looking to count the number of emails with given last names. The key would be a String (the last name), and the value would be an Integer (number of occurrences).

    You instantiate it as follows:

    Map<String, Integer> nameOccurrences = new HashMap<String, Integer>();
    

    To add a value to the map:

    nameOccurrences.put("Smith", 1);
    

    To check if a name is in the map:

    if (nameOccurrences.containsKey("Smith")) { ... }
    

    To get a value from the map:

    Integer occurrences = nameOccurrences.get("Smith");
    

    Note that names with different capitalization would be considered different keys. If you need to ignore capitalization, you’d have to do something like make the keys all uppercase before adding them to the Map.

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

Sidebar

Related Questions

Is there a good tool that can help to reverse engineer Java classes to
Is there a good class repository like PEAR for PHP for other languages such
I'm writing a C++ class to wrap sockets (I know that there are good
Is there any good way to deal with the class renaming refactor from Resharper
Is there a good ruby gem for a WYSIWYG editor that will easily work
Is there an equivalent of Monitor.Pulse and Monitor.Wait that I can use in conjunction
I want to create a class that can take different types of value in
Java and C# support the notion of classes that can't be used as base
I am writing a small program in C++. There is a class. Can you
Are there good reasons why it's a better practice to have only one return

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.