Ch. 17-18-19 Flashcards

You may prefer our related Brainscape-certified 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

A

\s*

25
Q

sc.skip(“skipthis”);

A

advances the position by skipping over “skipthis”. The substring skipped over must occur directly after the current position

26
Q

what is a complete token in Scanner?

A

a token inbetween two instances of the current delimiter

27
Q

what will be returned if two delimiters are right next to each other?

A

an empty string, which was “between” the two delimiters.

28
Q

sc.hasNext()

A

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
Q

was does a * after a delimiter mean?

A

zero or more occurrences of this delimiter

30
Q

symbol for non-word characters

A

\W

31
Q

what is the difference between passing arrays to methods and passing say integers.

A

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
Q

s.split(“a”)

not static

A

CREATES ARRAY by splitting the string into elements between the defined regex, in this case “a”

33
Q

what does | mean when used with split (ex: a|g)

A

split on a OR g

34
Q

how can split() be used to count the number of occurrences in a string

A

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
Q

why can’t for-each loops be used to initialize objects in an array?

A

because the loop uses a local variable to represent each individual element rather than the element itself.

36
Q

what would you use to compare objects that are elements of the array?

A

.equals

37
Q

what does NullPointerException mean?

A

the array has not been initialized yet, ergo is pointing to nothing

38
Q

what does null do?

A

sets all elements of the array to null, so that assigning values after the nullification only yields a NullPointerException

39
Q

System.arraycopy(fromArray, startIndex, endArray, toIndex, howMany)
STATIC: SYSTEM

A

copies a portion from one array to another array, and is STATIC to the System class.

40
Q

s.toCharArray()

A

turns a string into an array of chars.

41
Q

String.copyValueOf(ch)

STATIC VARIABLE FOR STRING CLASS

A

takes the char parameter and copies that into the String. It is a static variable for the String class.

42
Q

what is the logical size

A

the number of actual element in the array, as opposed to it’s initialized maximum value.

43
Q

what is the physical size?

A

myArray.length, since it is the initialized length of the array.

44
Q

Arrays.sort(myArray)

A

sorts the array in ascending order. STATIC meth

45
Q

Arrays.binarySearch(myArray, 2);

A

STATIC METHOD that returns the index of the last element that contains the value of the key.

46
Q

what has to happen to the array before binarySearch can occur?

A

it must be sorted in ascending order

47
Q

what does binary search return if it cannot find the key?

A

it returns the negated index of the element that would have come after the key, if it had been there.

48
Q

Arrays.equals(x, y)

A

compares two arrays. STATIC

49
Q

Arrays.fill(myArray, value)

A

static method; fills all spots in the array with the value.

50
Q

Arrays.toString(myArray)

A

turns it into a String

51
Q

enhanced for loop and read-only

A

the variable representing values in the for-each loop is local and cannot change the values of the elements.