Ch. 17-18-19 Flashcards

1
Q

compareTo()

  • return type
  • definition
  • explanation of the format
  • static or not
A
  • returns an int
  • compares the ASCII values of any object, returning a negative int if the object is less that the compared value, a positive if it is more, and zero if they are equal.
  • s.compareTo(“this is what I compare to”);
  • not static
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

what is the version of compareTo() that is not case sensitive

A

.compareToIgnoreCase

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

how many versions of indexOf are there? What do they all do if the search comes up empty?

A

6, and they all would return -1

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

indexOf(String str)

  • return type
  • definition
  • explanation of the format
  • static or not
A
  • returns an int
  • returns the index of the segment within the String
  • s.indexOf(“thing i want index of”);
  • not static
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

indexOf(String s, int from)

A

does the same thing as indexOf(String s) but starts checking from the index of the int parameter (from).

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

indexOf(char ch)

A

searches from left to right for the first occurrence of the char.

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

indexOf(int ascii)

A

similar to ch, except instead of giving a char it gives the ascii code of a char

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

indexOf(char ch, int from)

A

starting from the index ‘from’, checking for char ch.

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

indexOf(int ascii, int from)

A

similar to indexOf(char ch, int from) except the char is gotten from the character’s ascii code.

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

lastIndexOf()

A

with six versions, it is exactly the same as indexOf except it starts searching right to left rather than left to right

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

charAt(int indx)

  • return type
  • definition
  • explanation of the format
  • static or not
A
  • returns a char
  • returns the char that is at the specified index
  • s.charAt(3); This returns the character that is at index 3 of the string s.
  • not static
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

replace(char old, char new)

A

replaces all occurrences of the old char with the new char

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

replace(String old, String new)

A

replaces all occurrences of the old string with the new string

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

s.trim()

not static

A

removes the whitespace from both ENDS of the String while leaving the interior whitespaces alone.

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

contains(String ss)

  • return type
  • definition
  • explanation of the format
  • static or not
A
  • returns a boolean
  • returns true if the String contains the String ss
  • “something”.contains(“some”); or s.contains(“hay”);
  • not static
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

startsWith(String ss)

  • return type
  • definition
  • explanation of the format
  • static or not
A
  • return a boolean
  • returns true if the string starts with String ss.
  • s.startsWith(“something”); or “something”.startsWith(“some”);
  • not static
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

delimiters

A

a series of characters that separates the text presented to a scanner object into separate tokens

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

position of scanner

A

always BETWEEN two characters (like a cursor) never on top of one

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

what is the default delimeter

A

whitespace

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

sc.next()

A

moves position of scanner to right and returns the next complete token.

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

sc.findInLine(“ri”);

A

returns “ri” and places position right after “ri” in the string.

22
Q

what is the code for whitespace and more than one whitespace

A

\s and \s+

23
Q

sc.useDelimiter(“xxs”);

A

delimeter used is now “xxs”

24
Q

what is the code for zero or more whitespace characters

25
sc.skip("skipthis");
advances the position by skipping over "skipthis". The substring skipped over must occur directly after the current position
26
what is a complete token in Scanner?
a token inbetween two instances of the current delimiter
27
what will be returned if two delimiters are right next to each other?
an empty string, which was "between" the two delimiters.
28
sc.hasNext()
returns true if the String still has a next character for the Scanner position to move over, else it has reached the end of the String
29
was does a * after a delimiter mean?
zero or more occurrences of this delimiter
30
symbol for non-word characters
\\W
31
what is the difference between passing arrays to methods and passing say integers.
Integers and other types only transfer copies to the method (the original stays unchanged) while arrays actually physically pass the array, meaning that anything changed changes the original array.
32
s.split("a") | not static
CREATES ARRAY by splitting the string into elements between the defined regex, in this case "a"
33
what does | mean when used with split (ex: a|g)
split on a OR g
34
how can split() be used to count the number of occurrences in a string
the length of the split array minus 1 will yield the number of occurrences of whatever regex was defined, though if the regex is at very end, array.length is the number of occurrences.
35
why can't for-each loops be used to initialize objects in an array?
because the loop uses a local variable to represent each individual element rather than the element itself.
36
what would you use to compare objects that are elements of the array?
.equals
37
what does NullPointerException mean?
the array has not been initialized yet, ergo is pointing to nothing
38
what does null do?
sets all elements of the array to null, so that assigning values after the nullification only yields a NullPointerException
39
System.arraycopy(fromArray, startIndex, endArray, toIndex, howMany) STATIC: SYSTEM
copies a portion from one array to another array, and is STATIC to the System class.
40
s.toCharArray()
turns a string into an array of chars.
41
String.copyValueOf(ch) | STATIC VARIABLE FOR STRING CLASS
takes the char parameter and copies that into the String. It is a static variable for the String class.
42
what is the logical size
the number of actual element in the array, as opposed to it's initialized maximum value.
43
what is the physical size?
myArray.length, since it is the initialized length of the array.
44
Arrays.sort(myArray)
sorts the array in ascending order. STATIC meth
45
Arrays.binarySearch(myArray, 2);
STATIC METHOD that returns the index of the last element that contains the value of the key.
46
what has to happen to the array before binarySearch can occur?
it must be sorted in ascending order
47
what does binary search return if it cannot find the key?
it returns the negated index of the element that would have come after the key, if it had been there.
48
Arrays.equals(x, y)
compares two arrays. STATIC
49
Arrays.fill(myArray, value)
static method; fills all spots in the array with the value.
50
Arrays.toString(myArray)
turns it into a String
51
enhanced for loop and read-only
the variable representing values in the for-each loop is local and cannot change the values of the elements.