Hashtable Class in Java
In this post, you will learn how to work with the Hashtable class so that you can use that same knowledge and thus evolve.
- this class represents a collection of associations between pairs of values;
- the first element of the pair is called the key (identifier) and the other is called the content;
- the collection of associations between value pairs are organized according to the hash code of the key.
package com.caffeinealgorithm.programminginjava;
import java.util.Hashtable;
public class HashtableClass {
private Hashtable<String, Integer> people = new Hashtable<>();
public void Run() {
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: [Nelson Silva, Raquel Soares, Pedro Henrique]
Age of people: [25, 68, 100]
*/
Don’t forget to watch the video and you can always read this post in Portuguese.