Java Reference Flashcards
What is the method to compare strings?
The equals() method compares two strings, and returns true if the strings are equal, and false if not.
String myStr1 = “Hello”;
String myStr2 = “Hello”;
String myStr3 = “Another String”;
System.out.println(myStr1.equals(myStr2)); // Returns true because they are equal
System.out.println(myStr1.equals(myStr3)); // false
What is the purpose of the “final” keyword?
A non-access modifier used for classes, attributes and methods, which makes them non-changeable (impossible to inherit or override)
How do you change the value of an int into a String?
How do you change a String into an integer?
We need to use the method.valueOf.
String.valueOf(variable)
We use the method parseInt()
Integer.parseInt(variable)