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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T07:38:09+00:00 2026-06-01T07:38:09+00:00

I have a LinkedList that contains many objects. How can I find the number

  • 0

I have a LinkedList that contains many objects. How can I find the number and frequency of the distinct elements in the LinkedList.

  • 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-06-01T07:38:10+00:00Added an answer on June 1, 2026 at 7:38 am

    You can iterate the list with a for-each loop while maintaining a histogram.

    The histogram will actually be a Map<T,Integer> where T is the type of the elements in the linked list.

    If you use a HashMap, this will get you O(n) average case algorithm for it – be sure you override equals() and hashCode() for your T elements. [if T is a built-in class [like Integer or String], you shouldn’t be worried about this, they already override these methods].

    The idea is simple: iterate the array, for each element: search for it in the histogram – if it is not there, insert it with value 1 [since you just saw it for the first time]. If it is in the histogram already, extract the value, and re-insert the element – with the same key and with value + 1.

    should look something like this: [list is of type LinkedList<Integer>]

    Map<Integer,Integer> histogram = new HashMap<Integer, Integer>();
    for (Integer x : list) {
        Integer value = histogram.get(x);
        if (value == null) histogram.put(x,1);
        else histogram.put(x, value + 1);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have a list (EG: LinkedList<SomeObject> that contains elements ordered by a
I have two LinkedList objects that are always of the same size. I want
I have a LinearLayout view that already contains several elements. I want to add
If I have an LinkedList of Employee objects... Each employee has a Name, and
I have data that I would ideally want to represent as so: LinkedList<T>[] However,
I have an object that contains, as part of its data, a linked list.
I have LinkedList which contains let's say an element of type [q0/q1]. I would
I have a template linkedList that I would like to dynamically create head pointers
I have a class LinkedList clas that has a class called Node class Node
I want to be able to have LinkedList.contains() return true for a custom comparator.

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.