Answer:
Line of code: New String String line = "buttercup" ; buttercup String a = line.substring( 0 ); buttercup
(a new String is created,
containing all the characters of the original)String b = line.substring( 6 ); cup String c = line.substring( 9 ); (an empty string is created) String d = line.substring( line.length() ); (an empty string is created) String e = line.substring( line.length()+1 ); EXCEPTION String f = line.substring( -1 ); EXCEPTION
Play with substring()
Play with substring() using the following applet.
The parameter for substring() (in this applet) must be
an integer literal like 0 or 12.
|
Embedded Java applet removed: modern browsers do not support Java applets. The surrounding source code is retained for historical study.
|
Try some other strings than the one suggested. Be sure to enclose the characters of the string with quote marks. (However, the applet does not support escape characters in the string, so don't try tab characters.)
QUESTION 6:
The empty string "" is a legitimate String
object and thus has the substring( int from ) method.
What are the valid values for its from parameter?
(Test your answer with the above applet.)