Java: How to compare a string to a return from toString() -


basically when try compare class string using .equals returns false time.

for example:

myclass.java

public string tostring() {     return "apple"; } 

main.java

system.out.println(myclass.equals("apple")); 

will print "false".

what should use compare myclass string?

you need override definition form object class :

@override public string tostring() {   return "apple"; } 

and compare

system.out.println(myclass.tostring().equals("apple")); 

where myclass shall instance of myclass using code conventions.


Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -