What is the output of the following code? ArrayList list = new ArrayList(); java.util.Date d = new java.util.Date(); list.add(d); list.add(d); System.out.println((list.get(0) == list.get(1)) + " " + (list.get(0)).equals(list.get(1)));

Respuesta :

Answer:

true true

Explanation:

The code snippet first declare an arraylist called list. Then, a date object d is created. The object d is added to the arraylist twice.

Then inside the display statement, there are two boolean expressions. They both check if the element in index 0 and index 1 of the arraylist are the same and if they refer to the same object location in the memory.

The object in index 0 and index 1 are the same and they refer to the same object location in the memory hence the output is true true.

ACCESS MORE
EDU ACCESS
Universidad de Mexico