Java Reference
In-Depth Information
As you can see, this tells us that there are ten characters in the string stored in the name
variable.
Note: Bracket Notation
Another notation you can use to access a primitive value's properties are
square brackets:
name['length']; // note the property name is in
quote marks
<< 10
All properties of primitive values are immutable , which means that they're unable to be
changed. You can try, but your efforts will be futile:
name.length;
<< 10
name.length = 7; // try to change the length
<< 7
name.length; // check to see if it's changed
<< 10
A method is an action that a primitive value or object can perform. To call a method, we
use the dot operator [.] followed by the name of the method, followed by parentheses
(this is a useful way to distinguish between a property and a method―methods end with
parentheses). For example, we can write a string in all capital letters using the toUpper-
Case() method:
name.toUpperCase();
<< "HEISENBERG"
Or the toLowerCase() method, which will write my name in all lower-case letters:
name.toLowerCase();
<< "heisenberg"
Search WWH ::




Custom Search