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

  • Home
  • SEARCH
  • 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 764495
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T16:44:10+00:00 2026-05-14T16:44:10+00:00

My problem is as follows. I have an arraylist of integers. The arraylist contains

  • 0

My problem is as follows. I have an arraylist of integers. The arraylist contains 5 ints e.g[5,5,3,3,9] or perhaps [2,2,2,2,7]. Many of the arraylists have duplicate values and i’m unsure how to count how many of each of the values exist.

The problem is how to find the duplicate values in the arraylist and count how many of that particular duplicate there are. In the first example [5,5,3,3,9] there are 2 5’s and 2 3’s. The second example of [2,2,2,2,7] would be only 4 2’s. The resulting information i wish to find is if there are any duplicates how many of them there are and what specific integer has been duplicated.

I’m not too sure how to do this in java.

Any help would be much appreciated. Thanks.

  • 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-14T16:44:11+00:00Added an answer on May 14, 2026 at 4:44 pm

    To me, the most straightforward answer, would be using the Collections.frequency method. Something along the lines of this:

    // Example ArrayList with Integer values
    ArrayList<Integer> intList = new ArrayList<Integer>();
    intList.add(2);
    intList.add(2);
    intList.add(2);
    intList.add(2);
    intList.add(7);
    
    Set<Integer> noDupes = new HashSet<Integer>();
    noDupes.addAll(intList); // Remove duplicates
    
    for (Integer i : noDupes) {
        int occurrences = Collections.frequency(intList, i);
        System.out.println(i + " occurs " + occurrences + " times.");
    }
    

    If you want to, you could map each Integer with its number of occurrences:

    Map<Integer, Integer> map = new HashMap<Integer, Integer>();
    for (Integer i : noDupes) {
        map.put(i, Collections.frequency(intList, i));
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Problem 2b goes as follows: 2b. For each subject show the first year that
Problem: I have two spreadsheets that each serve different purposes but contain one particular
Our situation is as follows, but I'm curious about this problem in any situation.
Problem: I have an address field from an Access database which has been converted
I have the ViewValue class defined as follows: class ViewValue { private Long id;
I still have a problem with the splash screen. I don't want to use
I have a stringtoList ArrayList that needs to return tokens from a StreamTokenizer but
Problem (simplified to make things clearer): 1. there is one statically-linked static.lib that has
Problem: Ajax suggest-search on [ n ] ingredients in recipes. That is: match recipes
Problem: Given a list of strings, find the substring which, if subtracted from the

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.