operators - == and .equals() in java -
operators - == and .equals() in java -
this question has reply here:
how compare strings in java? 23 answers java string.equals versus == [duplicate] 20 answerson reading many articles figure out == compares if 2 operands referring same object.
how work primitive info types.
does compare values of operand?
does == work differently primitive info types , classes ?
kindly clarify
the “==” operator checking see if string objects (obj1 , obj2) refer exact same memory location. in other words, if both obj1 , obj2 different names same object “==” operator homecoming true when comparing 2 objects.
the equals() method behaves same “==” operator – meaning checks see if both objects reference same place in memory. but, equals method meant compare contents of 2 objects, , not location in memory. means if phone call equals() method compare 2 string objects, long actual sequence of characters equal, both objects considered equal.
primitive info types can not compared using equal() not objects. int, char can compared using == operator.
but when compare float , double may different results due binary conversion in machine. when comparing float values, consistent values, including special float.nan value, float.compare() best option. same applies double values.
java operators
Comments
Post a Comment