String Flashcards
It is a sequence of zero or more characters from the Unicode character set.
String
It is the sequence consisting of zero characters
Null string
What is it called when an object cannot be changed?
Immutable
Does a string change once created?
NO
If a string does not change once created, what happens instead?
Methods produce new strings from old ones
A representation for a string value within the program text
String Literal
In Java, it is a sequence of zero or more graphic characters from the Unicode character set or escape sequences, enclosed in double-quotes
String Literal
What is the syntax for string declaration?
String varname = value;
What does the following String function do?
charAt (int i)
Character at position i
What does the following String function do?
compareTo (String t)
Compare with t
What does the following String function do?
concat (String t)
Concatenation with t
What does the following String function do?
equals (String t)
Same characters as t
What does the following String function do?
equalsIgnoreCase
Same characters as t (ignoring case differences)
What does the following String function do?
indexOf (char c)
Position of the first occurence of c
What does the following String function do?
indexOf (String t)
Position of the first occurence of t
What does the following String function do?
length ()
Number of characters in String
What does the following String function do?
replace (char c, char d)
Replaces c with d
What does the following String function do?
substring (int f int t)
Substring from position f up to but not including t
What does the following String function do?
toLowerCase()
Equivalent string in all lowercase
What does the following String function do?
toUpperCase()
Equivalent string in all uppercase
What does the following String function do?
trim ()
Equivalent string without leading and trailing white space
What would the output be?
String str = “programming”;
char ch = str.charAt(2)
System.out.println(“Character at charAt(2): “ + ch);
ch = str.charAt(5)
System.out.println(“Character at charAt(5): “ + ch);
Character at charAt(2): o
Character at charAt(5): a
What would the output be?
System.out.println(“Character at charAt(2):” + ch);
String s1 = “Hello”;
String s2 = “Hello;”
String s3 = “HELLO”;
String s4 = “hello”;
System.out.println(“s1.compareTo(s2) “ + s1.compareTo(s2));
System.out.println(“s1.compareTo(s3) “ + s1.compareTo(s3));
System.out.println(“s1.compareTo(s4) “ + s1.compareTo(s4));
s1.compareTo(s2) 0
s1.compareTo(s3)
s1.compareTo(s4) -32
What value is returned if the content of the strings are the same when using the compareTo function?
0