Class 1, Part 2 |
Intro to Java 30-IT-396 |
|
Strings
-
A whole story of its own.
-
Strings
are characters enclosed in quotes. Any characters are fair game.
-
There is no primitive type for Strings, though the primitive type for an
individual character is char.
-
Thus, most of the String operations you do will be done with methods of
the java.lang.String object.
-
One exception is String concatenation. You can simply use the +.
-
If you attempt to concatenate a String with a non-String, the non-String
will be converted.
-
Primitives will be converted by the compiler.
-
Other objects will be converted via their toString() method. Every
object has a toString() method.
-
As an object, the String has a lot of 'exceptions to the rules' of normal
objects.
-
The String is the only object for which the "+" may be used to join two
instances together.
-
The String object is the only object that can be created without calling
a constructor. You can create a new String simply by setting
a String-type variable equal to string data in quotes.
-
You usually have to specifically tell the compiler to import a class that
you are using, except for classes in the java.lang.* package. Classes
that reside there are so common, they are imported automatically.
You guessed it, String resides in that package.
Substrings


Created by: Brandan
Jones January 4, 2002