Level 63 Level 65
Level 64

[Quiz] String Methods


100 words 0 ignored

Ready to learn       Ready to review

Ignore words

Check the boxes below to ignore/unignore words, then click save at the bottom. Ignored words will never appear in any learning session.

All None

Ignore?
String
The String class represents an immutable, e.g. cannot be changed, string of characters with its own methods.
int length ()
string length
char charAt()
ith character
ith through (j-1)st characters
String substring(int i, int j)
boolean contains(String sub)
does string contain sub as a substring
boolean startsWith(String pre)
does string start with pre
boolean endsWith(String post)
does string end with post
int indexOf(String p)
index of first occurance of p
int indexOf(String p, int i)
index of first occurance of p after i
String concat(String t)
this string with t appended
string comparison
int compareTo(String t)
String replaceAll(String a, String b)
result of changing a's to b's
String[] split(String delim)
strings between occurances of delim
boolean equals(String t)
is this string's value the same as t's
Character.isDigit(char a)
determines if character a is a digit
Should you use == to compare two strings?
No the relational operator only compares the objects and not the contents.
stringName.equals(otherStringName);
How is the equals method used?
stringName.compareTo(otherString);
How is the compareTo method used with strings?
string.charAt(index);
What does the charAt method do?
string.concat(string2)
What does the concat method do? Alternatively what else can you do?
string.substring(x, y);
What does the substring method do?
string.toUpperCase(); and string.toLowerCase();
What is are the methods to convert strings to uppercase and lowercase?
string.trim();
What does the trim method do?
string.replace('x', 'y'); string.replace("x", "y");
What is the replace and replaceFirst method?
Yes. Obj 3.1.
Are String objects immutable?
No. Obj 3.1.
Are String references immutable?
How do you reference a String that you don't initially assign?
You can't! new String("Bob"); is lost forever to your program unless you reference it like String uncle = new String("Bob");
If you haven't directed a String reference to it, it will be lost. Obj 3.1.
If you redirect a String reference to a new String, how do you reference the original string?
Which String methods use zero-based indexes?
All of them except for the second argument of substring(). Obj 3.1.
Which methods of String can you override?
None. The String class is final. Obj 3.1.
In the String literal pool. Obj 3.1.
Where are String literals kept by the JVM?
Strings have a method: length(); arrays have an attribute named length. Obj 3.1.
How is getting the length of an array different from getting the length of a String?
How are StringBuffer and StringBuilder related?
Their API's are identical with the exception that StringBuffer's methods are not synchronized. Obj 3.1.
StringBuilder, due to lack of synchronization. Obj 3.1.
Which class out of StringBuffer and StringBuilder will have the faster methods?
Can StringBuffer and StringBuilder values change?
Yes, unlike String, these objects can change without creating a new object. Obj 3.1.
They act on it. StringBuffer sb = new StringBuffer("test");
How do StringBuffer and StringBuilder methods affect the invoking object?
Is equals() a good way to compare StringBuffer and StringBuilder objects?
No! equals() is not overridden for these objects; it doesn't compare values. Obj 3.1.
How are chained methods evaluated?
From left to right. So MyString x = "tell"; String z = x.reverse().toUpper().subString(0, 1); Would leave "L" in z. Whereas x.subString(0,1).reverse().toUpper(), would leave "T". Obj 3.1.
What are important String methods?
charAt(), concat(), equalsIgnoreCase(), length(), replace(), substring(), toLowerCase(), toString(), toUpperCase(), and trim(). Obj 3.1.
What are important StringBuffer and StringBuilder methods?
append(), delete(), insert(), reverse(), and toString(). Obj 3.1.
What are important classes in java.io.
File, FileReader, BufferedReader, FileWriter, BufferedWriter, PrintWriter, and Console. Obj 3.2.
When you create a File object, how does that affect the filesystem?
It does not affect it directly at creation, more work is necessary. Obj 3.2.
Also, a File. Obj 3.2.
A File object represents a file. What object represents a directory?
What is a File object used for?
Managing files and directories, adding, renaming, and deleting. Obj 3.2.
createNewFile() and mkdir() respectively. Obj 3.2.
What methods in File create files and directories?
What is the primary use of FileReader and FileWriter classes?
They are low-level I/O classes useful for reading and writing files; but should usually be wrapped. Obj 3.2.
How are BufferedReader and BufferedWriter classes usually used?
They are usually "wrapped" around FileReader and FileWriter classes to give higher level and more convenient method usage on files. Obj 3.2.
How can PrintWriters be used?
They can wrap other Writers, but also operate directly on String and File objects. Obj 3.2.
What are new methods on PrintWriter since Java 5?
append(), format() and printf() [of course format and printf are the same] Obj 3.2.
Reading non-echoed input. Obj 3.2.
What are Console objects good for?
With System.console(). Obj 3.2.
How are Console objects instantiated?
What classes are used in Serialization?
ObjectOutputStream, ObjectInputStream primarily, and FileOutputStream and FileInputStream to create low-level streams that ObjectXxxStream classes use. Obj 3.3.
Implement Serializable. Obj 3.3.
What must a class do before its objects can be serialized?
What methods serialize and deserialize objects?
ObjectOutputStream.writeObject() and ObjectInputStream.readObject(), respectively. Obj 3.3.
How does marking an instance variable transient affect serialization of a class?
That variable will not be serialized even though the rest of the object's state will be. Obj 3.3.
How do you supplement a class's automatic serialization process?
By implementing writeObject and readObject methods in the class. Obj 3.3.
Yes! Embed calls to defaultWriteObject() and defaultReadObject() into your custom methods. Obj 3.3.
If you supplement a class's serialization with read and write Object methods, can you still take advantage of the automatic process?
They are also serializable. Obj 3.3.
If a superclass implements serializable, what does that mean for its subclasses?
The superclass' constructor will be invoked, along with all the superconstructors. Obj 3.3.
If a subclass implements serializable, but its superclass does not, what happens when the subclass is deserialized?
java.util.Date, java.util.Calendar, java.text.DateFormat, java.text.NumberFormat, and java.util.Locale Obj 3.4.
What are important classes for dealing with Dates, Numbers and Currency?
They are deprecated. Obj 3.4.
What is true of most Date class methods?
How is a Date stored?
As a long, specifically the number of milliseconds since Jan. 1, 1970. Obj 3.4.
What is the purpose of the Date class at this point?
It is used as a go-between the Calendar and Locale classes. Obj 3.4.
Date manipulation. Obj 3.4.
What is the Calendar class used for?
Using Calendar.getInstance(). Obj 3.4.
How do you get a Calendar instance?
What does Calendar's add() method do?
It adds or subtracts various pieces of dates. Obj 3.4.
What does Calendar's roll() method do?
It acts like add(), but only affects one specific part of the date. Adding 10 months with roll() would not increment the year even if it normally would. Obj 3.4.
How are DateFormat instances created?
DateFormat.getInstance() or DataFormat.getDateInstance(). Obj 3.4.
How can DateFormat objects and Locale objects be used together?
DateFormat styles are applied to Locale objects to produce a wide array of outputs for any given date. Obj 3.4.
What is the DateFormat.format() method used for?
To create Strings containing properly formatted dates. Obj 3.4.
DateFormat and NumberFormat. Obj 3.4.
What two classes are used in conjunction with Locale?
A specific, immutable Locale. Obj 3.4.
Both DateFormat and NumberFormat objects can be constructed with what?
How can you create a Locale?
Using a language or a language and country. Obj 3.4.
Regular expression. Obj 3.5.
What is regex short for?
What is a regular expression?
A pattern used to search for data within a (typically large) data source. Obj 3.5.
Using literal characters or metacharacters. Obj 3.5.
How does regex let you create search patterns?
How do metacharacters play into regex patterns?
They allow you to search for slightly more abstract data like "digits" or "whitespace". Obj 3.5.
Respectively, Digits, (white)Spaces, Word-characters and anything. Obj 3.5.
What do \d, \s, \w, and . metacharacters match?
What do the ?, * and + quantifiers mean?
Zero or one; zero or more, and one or more; respectively. Obj 3.5.
What does "greedy" mean in the context of regex?
That the entire string should be considered when finding a match. Obj 3.5.
What is important to consider with regex patterns in strings?
You must escape many metacharacters, for example: "\\d" Obj 3.5.
What does Pattern's compile() method do?
It turns a string into a regex pattern that can be used with matcher to parse a string. Obj 3.5.
What does Matcher's matches() method do?
Returns a boolean response to a Pattern's match of a given string. Obj 3.5.
What does Matcher's pattern() method do?
Returns a Matcher's pattern. Obj 3.5.
What does Matcher's find() method do?
Returns a boolean response to the first or next match of a given string. Obj 3.5.
What does Matcher's start() method do?
Returns the index of the previous match (or IllegalStateException) Obj 3.5.
What does Matcher's group() method do?
Returns the subsequence that is the previous match, possibly empty. Obj 3.5.
To tokenize Strings. Obj 3.5.
What is the primary usage of Scanner?
What does String.split() do?
Tokenizes an entire String at one time. Obj 3.5.
PrintStream. System.out.printf() or System.out.format(). Obj 3.5.
What class and typical usage do printf and format methods belong to and have?
How do format() and printf() differ?
Only in name. They are identical in functionality. Obj 3.5.
How is formatting accomplished with format() and printf()?
Through the use of formatting strings that are associated with primitive or string arguments. Obj 3.5.
left justify an argument
What flags apply to format() and printf()?
b boolean
What conversions apply to format() and printf()?
An exception will be thrown. Obj 3.5.
What happens if your conversion character doesn't match your argument type what will happen?
Can you use equals() to compare Integer and long?
No, long will get autoboxed to Long. Now you're comparing different types. Obj 3.1.
Can a serialized class have member classes that are not serialized?
Yes. But an exception will be thrown when you try to serialize the class. Obj 3.3.
What must happen with File operations?
You must catch Exceptions. Obj 3.2.
java.text Obj 3.4
What package is DateFormat in?
java.util Obj 3.4
What package is Locale in?