String class - The .equals() method
- .equals compares the values in objects
- String s1 = "Hello!';
- String s2 = "Hello!";
if (s1.equals(s2)) {
System.out.println("Same string");
}
Method header structure
(privacy) (return type) methodName(type parameter)
Public String toString();
- public means that we can call the method from another class (file)
- private means that we can only call the method from wtihin that class
- a return type indicates that a method call will evaluate to that type when called
String s = object.toString();
- if return type is void, that means we are not returning anything in the method
boolean expressions
ex:
!(i<2) && s.equals("cat")
- evaluates to true or false
- often contains boolean operators:
what do these expressions evaluate to?
int i = 3;
int k = -2;
String s = "cat";
(!(i < 2) && s.equals("cat")) //true
(!(k < 0) || (i > 5)) //false
//not(3<2)
//not -2<0 3>5