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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:23:01+00:00 2026-06-17T12:23:01+00:00

I have an arraylist of objects which contain information on calls made to a

  • 0

I have an arraylist of objects which contain information on calls made to a particular destination number. I have been trying to figure out the best way to search this list and return the number with the most occurrences as well as the count of these occurrences (to be called from another method in a linked class).

For instance:

I have this method which adds calls to the list by calling a random number in the address book

public void makeCall(Phonecall call)
    {
     call = new Phonecall();
     call.setDestination(anyNumber());
     call.setDuration(0 + (int)(Math.random() * (((balance/25) * 60) - 0) + 1));
     double cost = (call.getDuration()/60 * 25);
     balance = getBalance() - cost;
     updateCallHistory(call);
    }

and I then need to be able to search the arraylist callHistory it is updating and find the destination that has been called the most number of times and return that number and count.

Then I will call these values for each “phone” a person has and print the destination with the highest count across all “phones” as well as it’s count.

I’ve been looking around and have found information on finding occurrences of a particular object, but not been able to figure out how to check a particular field within that object instead of the object itself.

Sorry if this sounds convoluted but I’m getting quite confused and have run out of ideas, my hash mapping isn’t very strong yet and I couldn’t tweak the examples I’ve found to do what I want.

based on comments below I have

public void mostCalled(String[] args) 
    {
        Map<Phonecall,Integer> map = new HashMap<Phonecall, Integer>();  
        for(int i=0;i<callHistory.size();i++){              
            Integer count = map.get(callHistory.get(i));         
            map.put(callHistory.get(i), count==null?1:count+1);  
        }  
        System.out.println(map);
    }

but I do not know how to use the destination field of Phonecall instead of the object itself.

Would something like this be more suitable:

public void mostCalled(String[] args) 
    {
        Map<String,Integer> map = new HashMap<String, Integer>();  
        for(Phonecall call : callHistory)
        {
            Integer count = map.get(call.destination);         
            map.put(call.destination, count==null?1:count+1);  
        }  
        System.out.println(map);
    }
  • 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-17T12:23:01+00:00Added an answer on June 17, 2026 at 12:23 pm

    One solution would be to declare a Map<String, Integer> phoneCount which would hold a phone number as the key and the number of calls made to this number as the value.

    Then, you would loop through the ArrayList of PhoneCall objects and build the map. The record having the biggest value is the one you are looking for.

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

Sidebar

Related Questions

i have an issue with the understanding the arraylist which contain the objects from
I have an arraylist which contain objects of my own class. I want to
I have an arraylist of objects which contain multiple variables. I generate new objects
At the moment inside the class I have ArrayList which the objects are stored
Ok, so I have an ArrayList (arrBok) , which is full of book objects
I have two arraylist with a number of model objects.I want to find the
I have an object in my Action class which contains an arraylist of objects
I was trying to serialize an ArrayList which contains custom objects. I'm serializing it
I have static ArrayList<Batch> . i want to remove which object contain productcode This
I have a arraylist(eg.CustInfo) which contains a collection of objects(Cust_details,Cust_Auth) for java classes, which

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.