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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T00:40:34+00:00 2026-06-09T00:40:34+00:00

I was doing a research let say I have below array list List list=new

  • 0

I was doing a research let say I have below array list

    List list=new ArrayList();
      list.add(1);
      list.add(1);
      list.add(2);
      list.add(3);
      list.add(3);

Now as I can see the elements repeated in the list are 1 and 3 , now I want to create hashMap

Map hm = new HashMap();

and now in this HashMap I want key should be 1 and 3 and values should be 2 and 2 that is key 1 should have value 2 and key 3 should have value 2 that is the number of times is repeated is should be the value and the element that is repeated is to be stored as key Please advise how to achieve this..!

  • 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-09T00:40:35+00:00Added an answer on June 9, 2026 at 12:40 am

    You could simply loop over the list and:

    • if the item is not in the map, create it with value = 1
    • if the item already is in the map, get the value, increment increment it and put it back into the map

    ps: It is good practice to use generics:

    List<Integer> list = new ArrayList<Integer> ();
    

    and

    Map<Integer, Integer> hm = new HashMap<Integer, Integer> ();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been doing research on image file upload security for a while but can't
Preface: I am 100% new to the Flash and ActionScript world, doing research for
I am doing some research on developing thread safe applications. I know users can
I'm doing some research and I've come to a point where I have calculate
Doing some initial research on a new project and one of my requirements is
After doing research I have discovered that Google Maps (on a webpage) will not
I have a number (let's say, 34), and I want to find its next
I have been doing some research about this and have found a few similar
Im doing research on which one of these to use and I can't really
I'm doing research on coding requirements for medical applications but I can't find anything

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.