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
Q

How do you get an element at a given index of an ArrayList?

A

[ArrayList].get(int index)

26
Q

How do you return the index of an object in an arraylist?

A

[ArrayList].indexOf(Object o)

27
Q

How do you test if arraylist is empty?

A

[ArrayList].isEmpty()

28
Q

How do you remove an object at index of arraylist

A

[ArrayList].remove(int index)

29
Q

How do you remove all instances that are contained in a collection?

A

[ArrayList].removeAll(Collection> c)

30
Q

How do you remove a range of arralist?

A

[ArrayList].removeRange(int fromIndex, int toIndex)

31
Q

how do you get the size of arraylist?

A

[ArrayList].size()

32
Q

How do you get a sublist from arraylist?

A

subList(int fromIndex, int toIndex)

33
Q

how do you convert an arrayList to an array?

A

[ArrayList].toArray()

34
Q

How do you trim the arraylist to current size?

A

[ArrayList].trimToSize()

35
Q

What is the proper sytle for declaring an array of integers?

A

int[] arrayRef;

36
Q

What is an array variable set to if it does not contain a reference to an array?

A

null

37
Q

What are the default values for array primative types?

A

\u0000 for char
0 for numeric types
false for boolean

38
Q

What are the four steps of software design?

A
  1. Requirements specification
  2. System analysis
  3. System design
  4. Implementation
39
Q

How do you get the index of an enum value?

A

[ENUMCONSTANT].ordinal()

40
Q

What libraries are automatically included in java?

A

java.lang, java.util

41
Q

What happends when you use the final modifier on a method?

A

It can’t be overriden

42
Q

What happens when you invoke the final modifier on a class?

A

It cannot be extended.

43
Q

What exception may be thrown by invalid Down Casting?

A

RuntimeException