What is the result of the following code execution?

package tests;

import java.util.Hashtable;

public class Test {
  public static void main(String[] args) {
    Hashtable ht = new Hashtable();
    ht.put("1", "2");
    ht.put("2", "3");
    ht.put("3", "4");
    ht.put("4", "2");
    
    if(ht.contains("1")){
      System.out.print("1");
    }
    if(ht.contains("2")){
      System.out.print("2");
    }
    if(ht.contains("3")){
      System.out.print("3");
    }
    if(ht.contains("4")){
      System.out.print("4");
    }
  }
}
Explanation
Since contains method in a Hashtable class checks the presence of values ​​in the values list rather than keys list, then 234 will be printed out.

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Keep exploring
Java quizzes
Cosmo
Sign Up Now
or Subscribe for future quizzes