• Profile
  • Resume
  • Portfolio
  • Blog
Avatar

Nelson Silva

A human. Being. Coffee lover.

Blog

I Write My Thoughts Here

Dictionaries (Map) in Java

March 11, 2022 Java

In this post, you will learn how to work with dictionaries (Map) so that you can use that same knowledge and thus evolve.

  • dictionaries (which in Java programming language are created with the Map) are data structures that implement mappings (collection of associations between value pairs);
  • the first element of the pair is called the key (identifier) and the other is called the content.
package com.caffeinealgorithm.programminginjava;

import java.util.HashMap;
import java.util.Map;

public class DictionariesMap {
  public void Run() {
    Map<String, Integer> people = new HashMap<>();
    // Map people = new HashMap();

    people.put("Nelson Silva", 25);
    people.put("Larissa Fernandes", 37);
    people.put("Pedro Henrique", 52);
    people.put("Raquel Soares", 68);

    people.replace("Pedro Henrique", 100);
    people.remove("Larissa Fernandes");
    // people.clear();

    System.out.printf("Number of people: %s\n", people.keySet());
    System.out.printf("Age of people: %s", people.values());
  }
}

/*
  Number of people: [Pedro Henrique, Nelson Silva, Raquel Soares]
  Age of people: [100, 25, 68]
*/

Don’t forget to watch the video and you can always read this post in Portuguese.

Happy coding!

Previous Next

Categories

  • Announcements
  • Python
  • C#
  • Java
  • Go

Latest Posts

  • for Loop in Go
    May 5, 2022
  • Switch in Go
    May 4, 2022
  • Comparison Operators in Go
    May 3, 2022
+351913416022
contact@nelsonsilvadev.com
Porto, Portugal
Nelson Silva © 2022 All Rights Reserved