COP 2800 Chapter 9
String str = Double.toString(d);
To convert the double variable, d = 543.98, to a string, use the following statement:
double x = Double.parseDouble(str);
To convert the string, str = "285.74" to a double, use the following statement:
It creates a Float object. It initializes that object to 8.8. It assigns the object's address to the number variable.
What does the following statement do? Float number = new Float(8.8);
Wrapper class
What is term used for a class that is "wrapped around" a primitive data type and allows you to create objects instead of variables?
delimiter
What is the term used for the character that separates tokens?
diddl
What is the value of str after the following code has been executed? String str; String sourceStr = "Hey diddle, diddle, the cat and the fiddle"; str = sourceStr.substring(12,17);
ABC
What will be printed after the following code is executed? string str = "abc456"; int m = 0; while ( m < 6 ) { if (Character.isLetter(str.charAt(m)) System.out.print( Character.toUpperCase(str.charAt(m)); m++; }
str would reference "The cow jumped over the moon."
What would be the results of executing the following code? StringBuilder str = new StringBuilder(12); str.append("The cow"); str.append(" jumped over the "); str.append("moon.");
The statement performs autoboxing.
Look at the following code. Integer myNumber; myNumber = 5; Which of the following is TRUE about the second statement?
testing and converting char variables
The Character wrapper class provides numerous methods for:
True
The String class's valueOf() method accepts a value of any primitive data type as an argument and returns a string representation of the value.
16 characters
The no-arg constructor for a StringBuilder object gives the object enough storage space to hold this many characters.
substring
The term ________ commonly is used to refer to a string that is part of another string.
unboxing
This is the process of converting a wrapper class object to a primitive type.
ToString
Each of the numeric wrapper classes has a static ________ method that converts a number to a string.
9
For the following code, how many times would the for loop execute? String str = "1,2,3,4,5,6,7,8,9"); String[] tokens = str.split(","); for (String s : tokens) System.out.println(s);
True
If a non-letter is passed to the toLowerCase or toUpperCase method, it is returned unchanged.
split
Which of the following methods of the String class can be used to tokenize a string?
System.out.println(Integer.MAX_VALUE);
Which of the following statements will print the maximum value an int variable may have?