Java
Programming and Technical
Programming
Functions
Which is the correct option for comparing the contents of 2 String objects?
[1] == operator
[2] equals() method
[3] Both
Read Solution (Total 34)
-
- equal() method
- 8 years agoHelpfull: Yes(7) No(0)
- [1]== operator
because equals() method is used for reference comparison and == operator is used for content comparison. - 8 years agoHelpfull: Yes(6) No(5)
- by using equals method, because this method is available inside the object class
- 8 years agoHelpfull: Yes(2) No(0)
- equals()method is the correct option.
- 8 years agoHelpfull: Yes(2) No(0)
- option [2] is correct. In option [1],== operator compares only reference of the objects but option [2] compares the contents of the String objects.
- 8 years agoHelpfull: Yes(2) No(0)
- equals() method
Both == and equals() method is compares the object on the basis of reference, but the equals() method is overridden in all the wrapper classes and String class.
Inside these wrapper class and String class equals() method contains the logic to compare the objects on the basis of state.
So here equals() method will be useful. - 8 years agoHelpfull: Yes(2) No(0)
- equals() method
- 8 years agoHelpfull: Yes(1) No(1)
- both ==operator and equal method
- 8 years agoHelpfull: Yes(1) No(3)
- String.equals() method is preferred because == checks for reference type equality
- 8 years agoHelpfull: Yes(1) No(0)
- == operator is correct ans, because '==' is a comparision operator, it will check if the provided two operand values are same or not.( means content comparision)
equals() was defined in java.lang.object class, it was implemented in such a way that to provide comparision between two objects reference values, not to provide comparision between two objects contents.
- 8 years agoHelpfull: Yes(1) No(3)
- equals() method
- 7 years agoHelpfull: Yes(1) No(0)
- The correct answer is equals() method
In java string considered as a object not a type
Originally equals method is a method of object class which is overriden by String class in java
Basically == used for refrential equality where as equals() method used for a content equality - 7 years agoHelpfull: Yes(1) No(0)
- equals() method
- 8 years agoHelpfull: Yes(0) No(0)
- equals() method
- 8 years agoHelpfull: Yes(0) No(0)
- using equals() method
- 8 years agoHelpfull: Yes(0) No(0)
- equals() method is used for content comparison. and == operator is used for reference comparison.
- 8 years agoHelpfull: Yes(0) No(0)
- equals operator is for comparing 2 string objects
- 8 years agoHelpfull: Yes(0) No(0)
- Both..equal() and == can be used.
- 8 years agoHelpfull: Yes(0) No(0)
- equals() method is used to comapre the content and == operator is used for comparin the refrence of object.
- 8 years agoHelpfull: Yes(0) No(0)
- equals()method
- 8 years agoHelpfull: Yes(0) No(0)
- 2 equal method
- 8 years agoHelpfull: Yes(0) No(0)
- first one is correct because == operator is used for compare the two values
- 7 years agoHelpfull: Yes(0) No(1)
- equals(). where as == operator is used to compare references but equals() is used to compare contents of two strings.
- 7 years agoHelpfull: Yes(0) No(0)
- Arthemetic or logical operators cannot be used in strings
- 7 years agoHelpfull: Yes(0) No(0)
- 2) .equals()methood because this method is meant for content comparion in java. this method is overriden in string class and meant for content comparion
- 7 years agoHelpfull: Yes(0) No(0)
- .equals() used for content(values) comparison which retuens boolean value
== is used for reference (address) comparison - 7 years agoHelpfull: Yes(0) No(0)
- [2] equals() method
- 7 years agoHelpfull: Yes(0) No(0)
- == operator
- 7 years agoHelpfull: Yes(0) No(0)
- equals() method is correct answer because it compares the original content of string.
- 6 years agoHelpfull: Yes(0) No(0)
- equals() method
- 5 years agoHelpfull: Yes(0) No(0)
- both would be the final answer..
- 5 years agoHelpfull: Yes(0) No(0)
- == operator is best comparing two strings
- 5 years agoHelpfull: Yes(0) No(0)
- 3)both on
because equal() is method and == operator to compare an value - 5 years agoHelpfull: Yes(0) No(0)
- option 2 --> equal() method
- 4 years agoHelpfull: Yes(0) No(0)
Java Other Question