chapter 5 Flashcards

1
Q

What is string concatentation?

A

Placing one string before the other and combining them.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are the two ways the ways the + can be interpreted?

A
  1. If both operands are numeric, + means numeric addition.

2. If either operand is a String, + means concatenation.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is an immutable object?

A

An object that cannot be changed once it is created.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Is the String type immutable?

A

yes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What does String.length() return?

A

The number of characters in String.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What does String.charAt(1) return?

A

The char value at index 1 or throws IndexOutOfBoundsException - if the index argument is negative or not less than the length of this string.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What does String.indexOf() do?

A

Returns the index within this string of the first occurrence of the specified value, or -1.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What are the method signatures for indexOf()?

A
int indexOf(int ch)
int indexOf(int ch, int fromIndex)
int indexOf(String str)
int indexOf(String str, int fromIndex)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What does the String.substring(int beginIndex) do?

A

Returns a new string that is a substring of this string. `

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What are the method signatures for substring()?

A
String substring(int beginIndex)
String substring(int beginIndex, int endIndex)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Is the value at the endIndex in the substring() included ?

A

No.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What does toLowerCase() and toUpperCase() do?

A

toLowerCase(): converts any uppercase characters to lowercase in the returned string.
toUpperCase(): converts any lowercase characters to uppercase in the returned string.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What does the String.equals() method do?

A

Returns true if the given object represents a String equivalent to this string, false otherwise.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What does the String.equalsIgnoreCase() do?

A

Returns true if the argument is not null and it represents an equivalent String ignoring case; false otherwise.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What does the startsWith() do?

A

boolean startsWith(String prefix): Returns true if the character sequence represented by the argument is a prefix of the character sequence represented by this string; false otherwise. Note also that true will be returned if the argument is an empty string or is equal to this String object as determined by the equals(Object) method.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What does the endsWith() do?

A

boolean endsWith(String suffix): Returns true if the character sequence represented by the argument is a suffix of the character sequence represented by this object; false otherwise. Note that the result will be true if the argument is the empty string or is equal to this String object as determined by the equals(Object) method.

17
Q

What does the String.replace() do?

A

Replaces some value(s) with different value(s).

18
Q

What are the two method signatures for replace()?

A

replace(char oldChar, char newChar)

replace(CharSequence target, CharSequence replacement)

19
Q

What does the String.contains() do?

A

Returns true if and only if this string contains the specified sequence of char values.

20
Q

What do the trim(), strip(), stripLeading(), and stripTrailing() methods do?

A

Remove whitespace from the beginning, ending or both ends of the string.

21
Q

What is the difference between strip() and trim()?

A

strip() supports Unicode.

22
Q

What does the String.intern() do?

A

Returns a string that has the same contents as this string, but is guaranteed to be from a pool of unique strings.

23
Q

What is the StringBuilder class?

A

A class to create mutable strings.

24
Q

What are four common StringBuilder methods?

A

charAt(), indexOf(), length(), and substring().

25
Q

What does the StringBuilder.append() do?

A

Appends the string representation of the argument to this sequence and returns a reference to this StringBuilder.

26
Q

What does the StringBuilder.insert() do?

A

Adds characters to the StringBuilder as the requested index and returns a reference to this StringBuilder.

27
Q

What does StringBuilder.delete(int start, int end) do?

A

Removes the characters in a substring of this sequence. The substring begins at the specified start and extends to the character at index end - 1 or to the end of the sequence if no such character exists. If start is equal to end, no changes are made. Throws StringIndexOutOfBoundsException - if start is negative, greater than length(), or greater than end.

28
Q

What does StringBuilder.deleteCharAt(int index) do?

A

Removes the char at the specified position in this sequence. Throws StringIndexOutOfBoundsException - if the index is negative or greater than or equal to length().

29
Q

What does StringBuilder.replace(int start,
int end,
String str) do?

A

Replaces the characters in a substring of this sequence with characters in the specified String. The substring begins at the specified start and extends to the character at index end - 1 or to the end of the sequence if no such character exists. First the characters in the substring are removed and then the specified String is inserted at start. Throws StringIndexOutOfBoundsException - if start is negative, greater than length(), or greater than end.

30
Q

What does StringBuilder.reverse() do?

A

Causes this character sequence to be replaced by the reverse of the sequence and returns a reference to this object.

31
Q

What type of compilation error is thrown if you try to compare two different object types using ==?

A

incompatible types error.

32
Q

What is the string pool in Java?

A

The Java string constant pool is an area in heap memory where Java stores literal string values. The heap is an area of memory used for run-time operations. However, if you create a new instance of a String object, it will create a new string literal in the pool, even if one already exists.

33
Q

What does the String.intern() do?

A

Returns a string that has the same contents as this string, but is guaranteed to be from a pool of unique strings.

34
Q

What is the basic structure of an array?

A

int[] number = new int[3];

int = type of array
[] Array symbol (required)
3 = size of the array

35
Q

What is an example of an anonymous array?

A

int[] numbers = {1,2,3};

Its anonymous because the type and size were not specified.

36
Q

Where can the [] go when defining an array?

A

Before or after the name.

37
Q

What types of variables result from:

int ids[], types;

A

A variable named ids of type int[]

A variable named types of type int

38
Q

What method does Java have to print arrays nicely?

A

Arrays.toString(someArray);