|
|
||||||
|
||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
1.11 StringsStrings are treated somewhat special in Java, as in many other programming languages. They can be considered primitive data types, but in reality are complete Objects. Notice that String is capitalized, and hence it is an Object.To declare a String, we can follow several conventions:
Both of these expressions produce a String object, upon which methods from the String class can be used to act upon the String. Strings in Java have some overloaded operators, specifically the summation sign ( + ). Adding 2 Strings is the operation of concatenation:
To correct for the missing spaces, we can re-create the string as follows, and mix existing String objects and newly created String objects:
It is also possible to mix in numerical values when creating String objects:
Comparison of string values cannot be performed using the equality operator == . Instead, a method call to "equals" is required, for example:
|
||||||||||||||||||||||||||