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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T11:54:17+00:00 2026-05-16T11:54:17+00:00

OK so this is a BIT different. I have a new HashMap private Map<String,

  • 0

OK so this is a BIT different. I have a new HashMap

private Map<String, Player> players = new HashMap<String, Player>();

How do I remove last known item from that? Maybe somethign like this?

hey = Player.get(players.size() - 1);
Player.remove(hey);
  • 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-16T11:54:18+00:00Added an answer on May 16, 2026 at 11:54 am

    I’m a little bit confused. First of all, you’re saying that you’ve got a new ArrayList and you’re illustrating this with a line that creates a new HashMap. Secondly, does the Player class really have static methods like get(int) and remove(Object)?

    HashMap doesn’t have a particular order, ArrayList (as any other List) does.

    Removing from an ArrayList

    If you’ve got a list of players, then you can do the following:

    private List<Player> players = new ArrayList<Player>();
    // Populate the list of players
    players.remove(players.size() - 1);
    

    Here, I’ve used the remove(int) method of List, which allows to remove an item at an arbitrary index.

    Removing from a HashMap

    If you’ve got a map of players, there’s no such thing as “the last item”. Sure, you can iterate over the map and one of the items will pop out last, but that doesn’t mean anything. Therefore, first you have to find out what you want to remove. Then you can do the following:

    private Map<String, Player> players = new HashMap<String, Player>();
    // Populate the map of players
    // Find the key of the player to remove
    players.remove(toRemove);
    

    Here, I’ve used the remove(Object) method of Map. Note that in order to remove some key-value pair, you have to show the key, not the value.

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

Sidebar

Ask A Question

Stats

  • Questions 533k
  • Answers 532k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You should restrict your list to Numbers. That is the… May 17, 2026 at 12:21 am
  • Editorial Team
    Editorial Team added an answer You can write a small program to do this, using… May 17, 2026 at 12:21 am
  • Editorial Team
    Editorial Team added an answer Go this answer on CSTheory: Initialise x←v and y←−v. Then… May 17, 2026 at 12:21 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

Strange Question i guess but i have this bit of code in my page...
I have a class that acts like this at the moment: public class MyClass
My question might be little bit different or basic for advanced users here. I
I have been tasked with finding out what is causing an issue with this
I am getting a TestFunc is not defined error when this bit of code...
I am a bit new to Android. What I need to do is send
I want to run this function, or at least the bit that deletes the
Let's say that I have a form which runs a stored procedure. This stored
Sorry, I know that this topic has been covered a bit. I've read the
I have an app with a manifest that requires running as administrator, but part

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.