String/Builder/Array/List methods Flashcards

1
Q

charAt

A

(int)
returns char at index int.
String/StringBuilder.

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

String.indexOf

A

(int(char) | String, ~ | int)

returns first matching index of char or string, -1 otherwise. Second int can be used to set starting point of search.

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

substring

A

(int, ~ | int )
returns substring from index first int to either the end of the string or point second int, exclusive.
String/StringBuilder.

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

trim

A

()
returns string with surrounding white space (new lines, spaces, tabs) removed.
String.

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

String.replace

A

(char, char)|(string, string)

returns string with second char or string wherever first char or string is found.

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

length

A

()
returns the natural length of the string.
String/StringBuilder.

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

startsWith

A

(String, ~ | int)
returns boolean telling whether or not the string begins with the first string either at the beginning or at the index second int.
String.

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

endsWith

A

(String)
returns boolean telling whether or not the string ends with the specified string, starting from the bottom now we’re here.
String.

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

String Operators

A

+, +=, ==, !=. + may add numbers before strings.

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

StringBuilder Constructors

A

StringBuilder() - creates empty string builder with capacity of 16.
StringBuilder(int) - creates empty string builder with capacity of int.
StringBuilder(String) - created string builder with capacity of string + 16.

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

append

A

(*)
returns and mutates StringBuilder with * attached at the end. * can literally be anything. If it is an object whose class has not overridden toString(), classname@hashtag string will be used.
StringBuilder.

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

insert

A

(int, *) | (int, String | StringBuilder | char[], int, int)
returns and mutates StringBuilder with * (see append) inserted at first int index position. two ints can be added to specify a substring of the string-like second argument from index second int to the third int, exclusive if String or StringBuilder. if char[], the ints stand for starting position and length of substring.
StringBuilder.

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

reverse

A

()
returns and mutates string builder to its reverse.
StringBuilder.

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

StringBuilder.replace

A

(int, int, String)
mutates and returns StringBuilder: replaces index positions int to int exclusive with the string. There’s no problem if the second int is over the index; actually, it starts to knock off some of the StringBuilder’s characters without adding white white space.

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

subSequence

A

(int, int)
returns a string object wrapped around CharSequence reference from first index int to second, exclusive. does not mutate the string builder.
StringBuilder.

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

Array Initializations

A

Object[] aThing = {reference, reference};

Object[] aThing2= new Object[] {reference};

Object[] aThing3;
aThing3 = new Object[] {reference, reference};

Object[] aThing4= new Object[0];
aThing4[0] = reference;

17
Q

Array.length

A

array int length accessor.

18
Q

clone

A

()
returns a shallow cop: array of the same type with references to the same objects inside. ArrayList clone returns Object reference.
Array, ArrayList.

19
Q

ArrayList Creation

A
import java.util.ArrayList; or util.*;
ArrayList<type> aThing = new ArrayList<type>();
ArrayList<type> aThing2 = new ArrayList<>();
ArrayList<type> aThing3 = new ArrayList();
ArrayList aThing4 = new ArrayList<type>();
ArrayList aThing5 = new ArrayList();
you can place an argument int to specify capacity. default 10.
20
Q

add

A
(rightReference) | (int index, object)
add an item to the list and return true.
or
adds item to specified location and returns nothing.
ArrayList
21
Q

addAll

A

(rightArrayList) | (int index, rightArrayList)
These methods add all the references from one array list to the other, at a specified int index.
They return true.
Arraylist is really any collections but for the purposes of test 1, it’s array.
The argument array list type can be something that extends the type of the array list.
ArrayList.

22
Q

remove

A

(int) | (reference)
removes object at specified int index. returns the removed object. or removes first occurrence of object. returns true if accomplished, false otherwise. uses .equals()
ArrayList.

23
Q

contains

A

(reference)
returns true if reference is in there or false otherwise. uses .equals().
ArrayList.

24
Q

ArrayList.indexOf

A

(reference)

returns the index of the first occurrence of the element or -1. uses .equals().

25
Q

lastIndexOf

A

(reference)
returns the index of the final occurrence of the element or -1. uses .equals().
ArrayList.

26
Q

set

A

(int, rightReference)
replaces the object at index int with the reference. returns object which was replaced.
ArrayList.

27
Q

clear

A

()
clears all the elements of an array list. returns nothing.
ArrayList

28
Q

get

A

(int)
returns the element at the position in the list.
ArrayList.

29
Q

size

A

()
returns the number of elements in the list.
ArrayList.

30
Q

toArray

A

()
returns an array with references to the objects in the array list.
ArrayList.

30
Q

StringBuilder.indexOf

A

(String, ~ | int)

returns first matching index of string, -1 otherwise. Second int can be used to set starting point of search.

31
Q

concat

A

(String)
+ operator in method form
String

32
Q

delete

A

(int, int)
mutates and returns StringBuilder, removes characters inbetween indexes, exclusively.
StringBuilder

33
Q

deleteCharAt

A

(int)
mutates and returns StringBuilder, removes character at specified index.
StringBuilder