Java Reference Flashcards

1
Q

What is the method to compare strings?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the purpose of the “final” keyword?

A

A non-access modifier used for classes, attributes and methods, which makes them non-changeable (impossible to inherit or override)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How do you change the value of an int into a String?

How do you change a String into an integer?

A

We need to use the method.valueOf.
String.valueOf(variable)

We use the method parseInt()
Integer.parseInt(variable)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly