Ch 7: Characters, Strings, and the StringBuilder

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

The creators of Java chose ____ characters as the "extra" length for a StringBuilder object.

16

The ____ class contains standard methods for testing the values of characters.

Character

Any string value that is input into a program can be used in arithmetic operations.

False

If you try to use an index that is greater than 0 or less than the index of the last position in the StringBuilder object, you cause an error known as an exception and your program terminates.

False

The StringBuffer class is more efficient than the StringBuilder class because it can execute multiple threads during program execution.

False

The methods islowerCase() and toLowerCase() perform the same tasks.

False

The terms "literal string" and "string literal" have different meanings in Java programming.

False

When working with Strings, it is necessary to explicitly set a String to null.

False

When you compare Strings with the == operator, you are comparing their values, not their memory addresses.

False

To convert a String to an integer, you use the ____ class, which is part of java.lang and is automatically imported into programs you write.

Integer

Which of the following correctly declares and initializes a String object?

String greeting = "Hello";

A named object of the String class

String variable

A ____ is a class for storing and manipulating changeable data that is composed of multiple characters.

StringBuilder

A String variable name is not a simple data type.

True

In a compareTo() method, programmers often do not need specific return values but want to determine if a value is positive or negative.

True

When you must determine whether a String is empty, it is more efficient to compare its length to 0 than it is to use the equals () method.

True

A literal string is a(n) ____ object.

anonymous

A literal string is called a(n) ____.

anonymous object

An unnamed object

anonymous object

Add characters to the end of a StringBuilder object

append()

A StringBuilder object contains a memory block called a _____, which might or might not contain a string.

buffer

A memory block

buffer

Memory block

buffer

The method header of the equals() method within the String class is ____. a. public boolean equals(Strings) b. private boolean equals(String s) c. public boolean equals(String s) d. public boolean equals(Character s)

c. public boolean equals(String s)

Length of a buffer

capacity

The ____ method requires an integer argument that indicates the position of the character at that position, starting at 0.

charAt()

When the String class ____ method is used to compare two Strings, it provides additional information to the user in the form of an integer value.

compareTo()

Appending strings

concatenation

System.out.println("Your name is " + yourName); The above statement is an example of ____, which is used to join Strings.

concatenation

The String class ____ method evaluates the contents of two String objects to determine if they are equivalent.

equals()

The String class ____ method is similar to the equals() method. As its name implies, this method does not consider case when determining if two Strings are equivalent.

equalsCase()

Object that can't be changed

immutable

Strings and other objects that can't be changed are known as ____.

immutable

Determines whether a specific character occurs within a String

indexOf()

The Character class ____ from java.lang.Object.

inherits

Add characters at a specific location within a StringBuilder object

insert()

The ____ method lets you add characters at a specific location within a StringBuilder object.

insert()

The ____ method returns the length of a String.

length()

A(n) ____ comparison is based on the integer Unicode values of the characters.

lexicographical

String oneStr = "Welcome Jim" String twoStr = "Welcome Joe" Given the lines of code above, which of the following regionMatches() expressions will result in a value of true?

oneStr.regionMatches(0, twoStr, 0, 7)

Takes a String argument and returns its double value

parseDouble()

The ____ method takes a String argument and returns its double value.

parseDouble()

Assume that aName refers to Roger. What is returned by aName.compareTo("Robert");

positive number

A(n) ____ is a variable that holds a memory address.

reference

The ____ method allows you to replace all occurrences of some character within a String.

replaceCharacter()

To alter just one character in a StringBuilder, you can use the ____ method, which allows you to change a character at a specified position within a StringBuilder object.

setCharAt()

Change the length of a string in a StringBuilder object

setLength()

Consider the statement: int anInt = Integer.parseInt("649"); You can tell that parseInt() is a(n) ____ method because you use it with the class name and not with an object.

static

The ____ method and the startsWith() method each take a String argument and return true or false if a String object does or does not end or start with the specified argument, respectively.

strEnd()

Takes two integer arguments: a start position and an end position

substring()

The methods of the Character class that begin with ____ return a character that has been converted to the stated format.

to

Returns the lowercase equivalent of the argument

toLowerCase()

The ____ method converts any object to a String.

toString()

When you declare a variable of a basic, primitive type, such as int x = 10;, the memory address where x is located holds the ____.

value of 10

Class or object that wraps around a simpler element

wrapper


Ensembles d'études connexes

Fin 7, FIN C5, C1 - Nature of Law, C1 - Nature of Law

View Set

World Geography Semester 1 Final 9th Grade

View Set

Chapter 42- Sonographic and Doppler Evaluation of the Female Pelvis

View Set

Chapter 33 Assessment and Management of Patients with Allergic Disorders

View Set

Physics final practice quizes 29,30,32

View Set

Overview of the business of healthcare

View Set

CLST Quiz 2 Terms and People/Gods/Places

View Set