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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T20:32:25+00:00 2026-05-30T20:32:25+00:00

For example, say I have an ArrayList that could contain the following values: x

  • 0

For example, say I have an ArrayList that could contain the following values:

x
x
x
y
y

Now what I want to retrieve is the number of x and x and I want to be able to differentiate what I have, either x or y because in actuality, I could have any object in the ArrayList and I have to be able to tell them apart.

What I was thinking of doing was first converting the ArrayList into a LinkedHashSet, which would keep the ordering and remove the duplicates so I would just have x and y But how would I get the number of each and associate it with the proper element?

Overall what I want to do is to be able to write a toString method that will let me output:

x3y2

But without knowing that x and y are the elements because they could have been something else like z or w.

  • 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-30T20:32:26+00:00Added an answer on May 30, 2026 at 8:32 pm

    Check out the Multiset in google guava: http://docs.guava-libraries.googlecode.com/git-history/v11.0.2/javadoc/com/google/common/collect/Multiset.html

    Example:

    Multiset<String> strings = HashMultiset.create(arrayList);
    int countX = strings.count("x"); // the count of x
    

    More examples can be found on the Guava wiki.

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

Sidebar

Related Questions

To use as an example: lets say that I have 2 EditText s and
Say I have the following code: <div onclick='location.href=http://www.example.com/'> <a href='#' onclick='alert(blah)'>click</a> </div> Is there
Let's say I have this url: www.example.com/test.php?page=4 How do i retrieve the value of
Say I have the following java code: Object myObj = new ArrayList(); List myList
This is for Delphi Prism. Say, I have the following enum SET type that
I have ArrayList of Strings. I need to randomize it by hash number. Example:
A simple example: Let's say I have one alias being sourced somewhere as: alias
i have problem use link_to_remote link_to_remote document example say link_to_remote Delete this post, :update
Say I have a site on http://example.com . I would really like allowing bots
Say I have this url: http://site.example/dir/ In this folder I have these files: test.ascx.cs

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.