Strings
We have already encountered the Java String class:
- Can define variables and parameters that reference strings.
You can assign values to string names, and you can write methods
that return Strings as results. Recall from the unit on GUI items:
String newLevel = (String)level.getSelectedItem();
- Can describe strings in programs by placing double quotes around
a sequence of characters:
msg.setText("Got me!");
- Can glue together strings; can glue together a string and a
numeric value to make a new string:
mouseCount.setText("You clicked " + count + " times.");
- Can determine if two strings look the same by using the
"equals" method. Again, recall from the unit on GUI:
if (newLevel.equals("Easy")) ...
- You've been told to always use "equals" to check for
equality, rather than "=="