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

Related Questions

I have this bit of javascript written with jQuery 1.2.5. It's contained inside the
I have this bit of script to widen a text box on mouseover and
I have this bit of code I found on the web at the end
Well, I have this bit of code that is slowing down the program hugely
This a bit of strange one.... We have an internal web app that runs
Strange Question i guess but i have this bit of code in my page...
I'm trying to understand this bit of code: in display.php: <html> ... <body> <table>
How can I fetch images from a server? I've got this bit of code
Ok, this is bit of an obscure question, but hopefully someone can help me
Using c#, VS2005, and .NET 2.0. (XP 32 bit) This is a Winforms app

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.