Java Flashcards

1
Q

How do you find a character at a certain index?

A

[String].charAt(int index)

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

How do you find the length of a string?

A

[String].length()

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

How do you obtain a sub string?

A

[String].substring(int beginIndex, int endIndex)

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

How do you test if the string contains a character?

A

[String].contains(CharSqequence s)

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

How do you replace all occurrences of a character?

A

[String].replace(char old, char new)

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

how do you convert a String to lowercase?

A

[String].toLowerCase()

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

How do you convert a String to uppercase?

A

[String].toUpperCase()

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

How do you remove spaces from the beginning and end of a String?

A

[String].trim()

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

How do you test if a String is empty>

A

[String].isEmpty()

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

How do you split a string?

A

[String].split(String regex, int limit)

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

How do you declare a new scanner for user input?

A

Scanner in = new Scanner(System.in)

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

How do you create a new scanner for a file?

A

Scanner in = new Scanner(File source)

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

How do you check if scanner can still read?

A

[Scanner].hasNext() or [Scanner].hasNextLine()

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

How do you grab next line from scanner?

A

[Scanner].nextLine()

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

How do you create a new File object?

A

File file = new File(“filename.txt”)

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

how do you declare array list?

A

ArrayList al = new ArrayList()

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

what are the three arraylist constructors?

A

ArrayList()
ArrayList(Collection extends E> c)
ArrayList(int initalCapacity)

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

How do you add an element to the arraylist?

A

[ArrayList].add(E e)

19
Q

How do you insert an element at a specific index of an arraylist?

A

[ArrayList].add(int index, E e)

20
Q

How do you add a collection to arraylist>

A

[ArrayList].addAll(Collection extends E> c)

21
Q

How do you clear an arraylist?

A

[ArrayList].clear()

22
Q

How do you create a shallow copy of the arraylist?

A

[ArrayList].clone()

23
Q

How do you test if an arraylist contains an Object?

A

[ArrayList].contains(Object o)

24
Q

How do you ensure a minimum capacity for an arrayList?

A

[ArrayList].ensureCapacity(int minCapacity)

25
How do you get an element at a given index of an ArrayList?
[ArrayList].get(int index)
26
How do you return the index of an object in an arraylist?
[ArrayList].indexOf(Object o)
27
How do you test if arraylist is empty?
[ArrayList].isEmpty()
28
How do you remove an object at index of arraylist
[ArrayList].remove(int index)
29
How do you remove all instances that are contained in a collection?
[ArrayList].removeAll(Collection> c)
30
How do you remove a range of arralist?
[ArrayList].removeRange(int fromIndex, int toIndex)
31
how do you get the size of arraylist?
[ArrayList].size()
32
How do you get a sublist from arraylist?
subList(int fromIndex, int toIndex)
33
how do you convert an arrayList to an array?
[ArrayList].toArray()
34
How do you trim the arraylist to current size?
[ArrayList].trimToSize()
35
What is the proper sytle for declaring an array of integers?
int[] arrayRef;
36
What is an array variable set to if it does not contain a reference to an array?
null
37
What are the default values for array primative types?
\u0000 for char 0 for numeric types false for boolean
38
What are the four steps of software design?
1. Requirements specification 2. System analysis 3. System design 4. Implementation
39
How do you get the index of an enum value?
[ENUMCONSTANT].ordinal()
40
What libraries are automatically included in java?
java.lang, java.util
41
What happends when you use the final modifier on a method?
It can't be overriden
42
What happens when you invoke the final modifier on a class?
It cannot be extended.
43
What exception may be thrown by invalid Down Casting?
RuntimeException