Basic Syntax Flashcards

1
Q

for loop

A

for (statement 1; statement 2; statement 3) {
// code block to be executed
}

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

number of elements in array

A

array.length

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

immutable list w/ literals

A

List<Integer> list=Arrays.asList(1, 2, 3);</Integer>

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

char array from String

A

char[] ch = str.toCharArray();

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

hash set from list

A

Set<String> set = new HashSet<>(list);</String>

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

number of elements in a queue

A

q.size()

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

java max function

A

Math.max

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

Create a HashMap

A

private HashMap<Integer, Integer> memo = new HashMap<Integer, Integer>();

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

Check if HashMap has key

A

hashMap.containsKey(i)

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

substring of a string

A

public String substring(int begIndex, int endIndex);

beginIndex : the begin index, inclusive.
endIndex : the end index, exclusive.

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

parse string to int

A

int i=Integer.parseInt(“200”);

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

number of characters in a string

A

s.length()

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

get larges integer values

A

Integer.MAX_VALUE

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

insert object into hashset

A

hashSet.add()

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

append an element to the end of a list

A

list.add(E e)

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

remove element from specific index of a list

A

list.remove(intindex)

17
Q

number of elements in a list

A

list.size()

18
Q

Removes the mapping for the specified key from this map if present.

A

HashMap.remove(Object key)

19
Q

Returns the element at the specified position in this list.

A

List.get(int index)

20
Q

Returns a double value with a positive sign, greater than or equal to 0.0 and less than 1.0.

A

Math.random()

21
Q

Create a Queue

A

Queue is an interface. The following classes implement it, PriorityQueue, LinkedList and ArrayDeque

22
Q

Add element to Queue

A

offer()

23
Q

Retrieve but do not remove item from Queue

A

peek()

24
Q

Retrieves and removes the head of the queue, or returns null

A

poll()