- Esecutori
-
Impara
Impara Python Esempi eseguibili, NumPy, pandas e altro Impara l'IA / Machine LearningReti neurali, ML e LLM da zero Impara C e C++ Puntatori, memoria, STL e C++ moderno Impara C#Fondamenti, OOP, LINQ, async ed esercizi .NET Impara MatplotlibGrafici a linee, barre, dispersione e torta con visualizzatori Impara RustOwnership, trait, gestione degli errori e thread Impara GoSlice, interfacce, goroutine e canali Algoritmi Python Ricerca, ordinamento, ricorsione e visualizzazioni O(n) Algoritmi C e C++ Confronta le implementazioni in C e C++ Programmazione per bambini Impara a programmare giocando!
- QuizNuovo
- SfideNuovo
- Per docentiNuovo
- Aggiornamenti
- Offrimi un caffè
Quiz di Java: HashMap
This Java quiz tests how HashMap really behaves. You will predict what put(), get(), getOrDefault(), merge() and computeIfAbsent() return, see why keys need both equals() and hashCode(), and handle null values safely.
Domanda di esempio
Domanda 1 di 10What does this print?
import java.util.HashMap;
import java.util.Map;
public class Main {
public static void main(String[] args) {
Map<String, Integer> m = new HashMap<>();
System.out.println(m.put("a", 1) + " " + m.put("a", 2) + " " + m.get("a"));
}
}
Mostra la risposta
C. null 1 2 put() returns the value previously stored for the key: null the first time, then 1. The second put() replaces the value, so get() returns 2.
Cosa copre questo quiz
put()returns the old value,get()returnsnullwhen missing- Counting and grouping with
merge()andcomputeIfAbsent() - Keys need matching
equals()andhashCode() nullvalues,containsKey()and unboxing- Iteration order:
HashMap,LinkedHashMap,TreeMap
Domande frequenti
Serve un account?
No. Chiunque può giocare. Accedi per salvare XP, serie, badge e cronologia.
Posso rifarlo?
Sì. Il tuo miglior punteggio resta salvato, e domande e risposte vengono mescolate ogni volta.