R 39
R 39
Answer: �= =� does shallow comparison, It retuns true if the two object points to
the same address in the memory, i.e if the same the same reference
�equals()� does deep comparison, it checks if the values of the data in the object
are same
Question: What would you use to compare two String variables - the operator == or
the method equals()?
Answer: I'd use the method equals() to compare the values of the Strings and the ==
to check if two variables point at the same instance of a String object
Answer: String is an immutable class, i.e you cannot change the values of that
class
Example:
Question: What will be the result if you compare StringBuffer with String if both
have same values
Answer: It will return false as you cannot compare String with StringBuffer
Answer: A collection has no special order and does not reject duplicates
A list is ordered and does not reject duplicates
A set has no special order but rejects duplicates
A map supports searching on a key field, values of which must be unique
Answer: Arrays are fast to access, but are inefficient if the number of elements
grow and if you have to insert or delete an element
Answer: Vector methods are synchronized while ArrayList methods are not
Answer: Hashtable does not store null value, while HashMap does
Hashtable is synchronized, while HashMap is not