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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T11:28:12+00:00 2026-06-09T11:28:12+00:00

I have a Hashmap and i am struggling on how to print a single

  • 0

I have a Hashmap and i am struggling on how to print a single key and value. i am able to print all of them but would like to know how to just print one of them thanks

import java.util.HashMap;


public class Coordinate {

static class Coords {
    int x;
    int y;

    public boolean equals(Object o) {
        Coords c = (Coords) o;
        return c.x == x && c.y == y;
    }

    public Coords(int x, int y) {
        super();
        this.x = x;
        this.y = y;
    }

    public int hashCode() {
        return new Integer(x + "0" + y);
    }

    public String toString()
    {
        return x + ";" + y;
    }


}

public static void main(String args[]) {

    HashMap<Coords, String> map = new HashMap<Coords, String>();

    map.put(new Coords(65, 72), "Dan");


    map.put(new Coords(68, 78), "Amn");
    map.put(new Coords(675, 89), "Ann");

    System.out.println(map.size());
    System.out.println(map.toString());

}
}

At the moment it shows

3
{65;72=Dan, 68;78=Amn, 675;89=Ann}

but would like it to just show

65;72=Dan

thanks for looking

  • 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-09T11:28:13+00:00Added an answer on June 9, 2026 at 11:28 am

    The Map.get(K) method allows you to retrieve the value of a desired key. So you can do this:

    Coords c = new Coords(65,72);
    System.out.println(c + " -> " + map.get(c));
    

    This works for any sort of Map, including HashMap and TreeMap. You can also obtain a set of all keys in the map using Map.keySet().

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

Sidebar

Related Questions

I have a HashMap where the key is a word and the value is
I have a hashmap with some information(key and value) in a perl file. I
I have a hashmap that is 101 keys in size, but I know for
I have hashmap and its keys are like folder/1.txt,folder/2.txt,folder/3.txt and value has these text
I have an Hashmap <integer, Arraylist<Double>> . I would like to make a copy
I have a Hashmap that, for speed reasons, I would like to not require
I have HashMap object contains a key x-y-z with corresponding value test-test1-test2 . Map<String,String>
I have a HashMap where the key is of type String and the value
I would like to have a HashMap<String, String> , that every day at midnight,
I have HashMap like: static HashMap<String,ArrayList<Media>> mediaListWithCategory=new HashMap<String,ArrayList<Media>>(); I have value like: January: -Sunday

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.