Quiz de Java: HashSet

This Java quiz covers HashSet and its relatives LinkedHashSet and TreeSet. You will predict what add() returns, how sets treat your own classes and records, how set operations work and why changing an element inside a set breaks it.

Médio 10 perguntas ~6 minutos Aprovação com 80% Java 17

Escolha um modo

Jogando como visitante: entre para guardar seu XP e sua sequência.

Pergunta de exemplo

Pergunta 1 de 10

What does this print?

import java.util.HashSet;
import java.util.Set;

public class Main {
    public static void main(String[] args) {
        Set<String> s = new HashSet<>();
        System.out.println(s.add("a") + " " + s.add("a") + " " + s.size());
    }
}
Mostrar a resposta

B. true false 1 add() returns true only when the element was not already in the set. The second a is a duplicate, so it returns false and the size stays 1.

O que este quiz cobre

  • add() returns false for duplicates
  • How equals() and hashCode() define duplicates
  • Records as set elements
  • retainAll() and other set operations
  • HashSet vs LinkedHashSet vs TreeSet

Perguntas frequentes

Preciso de uma conta?

Não. Qualquer pessoa pode jogar. Entre para guardar seu XP, sequência, badges e histórico.

Posso refazer?

Pode. Sua melhor nota fica salva, e as perguntas e respostas são embaralhadas a cada vez.