Pre-AP Computer Science 1 Strings

Word processing term papers
Writing memoirs
Sending email messages
Responding to surveys
Placing online orders
Registering products

Give an example of something that involves String Processing.

A class

Is String a primitive data type, or a class?

upper-case letters

All Java classes start with _________________________.

methods

String has many _______ that facilitate string manipulations.

A set of characters that behaves as a single unit

What is a String?

upper-case letters
lower-case letters
numerical digits
symbols

The characters in a String include 4 things. List them.

A set of characters delimited with double quotations

What is a string literal?

City
"Dallas

Consider this statement: String city = "Dallas"; What is the string variable and what is the string literal?

Yes

Whenever the new keyword is used in Java, it means a new object is being constructed.
Is it possible to construct a new object in Java without using the new operator?

String city2 = new String();
city2 = "Dallas";
String city4 = new String(city2);
char place[] = ('D','a','l','l','a','s');
String city5 = new String(place);

Consider this statement: String city1 = "Dallas";
Create 4 more String objects, city2, city3, city4, and city5, which will also store "Dallas".
Each object needs to be created in a different manner.

Joining 2 or more strings together

What is concatenation?

Anytime double quotes are involved

When does the plus [ + ] operator perform concatenation?

String fullName = firstName + LastName;

Assume firstName equals "John " and lastName equals "Smith".
Write a program statement that will concatenate the 2 variables into a fullName.

50100

Consider the statement String myNum = "50" + "100". What does myNum equal?

150

Consider the statement int myNum = 50 + 100. What does myNum equal?

The numbers of characters in a string

What does the length method return?

Field
Method

With arrays, length is a _______. With strings, length is a _______.

The space counts as a character

Look at the output of program Java1203.java. If "Argentine" has 9 characters and "Tango" has 5 characters, how is it that "Argentine Tango" has 15 characters when 9 + 5 = 14?

Whitespace characters

What are invisible characters called?

0
The length minus 1

You will note that not only do strings and arrays share the concept of length, they also share the concept of indexes. You will also note that just like arrays, the first index is _______ and the last index is ______________.

No

In some languages like C++, a string is an array of characters. Is this true in Java?

charAt

What method accesses the character at the index of the method argument?

+=

Characters can be concatenated to the end of a String object using the _______ operator.

int,double,char and boolean

List 4 primitive data types.

String.valueOf

Which static method coverts simple data types to String objects?

It is called with the name of the class.
A String Object is not required

Refer to the previous question. Why is this method called a static method?

Integer.parseInt();

Which methods will convert a String to an int?

Double.parseDouble();

Which methods will convert a String to a double?

primitive

The equality operator == is strictly reserved for the __________ data types.

You should use the equals method

What should be used instead of the == operator when comparing Strings?

s1 goes alphabetically before s2

System.out.println(s1.compareTo(s2));
What does it means if this program statement displays a negative number?

s1 goes alphabetically after s2

System.out.println(s1.compareTo(s2));
What does it means if this program statement displays a positive number?

s1 and s2 are equal

System.out.println(s1.compareTo(s2));
What does it means if this program statement displays 0?

A set of consecutive characters from String s1, starting at index j, and ending at index k-1

s1 = "Aardvark";
s2 = s1.substring(j,k);
What does substring return?

First occurrence of a substring

What does indexOf return in a substring?

Last occurrence of a substring

What does lastIndexOf return in a substring?

A string such that every occurrence of the old character is replaced by the new character

What does the method replace return?

A String where all letters are upper-case

What does toUpperCase return?

A String where all letters are lower-case

What does toLowerCase return?

Class method

Is valueOf a class or object method?