Java colllections FrameWork Flashcards

(19 cards)

1
Q

What is the JCF?

A

It is a set of classes and interfaces that come by default with java and provide ready-to-use data structures and algorithms for storing, retriving, and manipulating groups of objects efficiently

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

What are 3 collections you know from Java?

A

List, Sets, and Maps

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

What is a List?

A

It is an orderd collection of elments, where elements can be duplicated, and elements can be accesed by their index the collection.

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

What is a set?

A

It is a collection of elements in which duplicate elements are not allowed.

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

What is a map?

A

It is a collection of key-value pairs.

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

How do you create and use an Array in Java?

A

```java
String[] fruits = {“Apple”, “Banana”, “Orange”};

System.out.println(fruits[0]);
~~~

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

How do you access elements in an Array in Java?

A

```java
String firstFruit = fruits[0];
System.out.println(firstFruit);
~~~

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

How do you create and add elements to an ArrayList in Java?

A

```java
ArrayList<String> colors = new ArrayList<>();
colors.add("Red");
colors.add("Blue");
~~~</String>

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

How do you access elements in an ArrayList in Java?

A

```java
String color = colors.get(0);
System.out.println(color);
~~~

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

How do you remove an element from an ArrayList in Java?

A

```java
colors.remove(“Red”);
colors.remove(0); // remove by index
~~~

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

How do you create a LinkedList and add elements in Java?

A

```java
LinkedList<String> names = new LinkedList<>();
names.add("Alice");
names.add("Bob");
~~~</String>

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

How do you access elements in a LinkedList in Java?

A

```java
String name = names.get(0);
System.out.println(name);
~~~

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

How do you remove an element from a LinkedList in Java?

A

```java
names.remove(“Alice”);
names.remove(0); // remove by index
~~~

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

How do you create a HashMap and add key-value pairs in Java?

A

```java
HashMap<String, Integer> scores = new HashMap<>();
scores.put(“Math”, 90);
scores.put(“English”, 85);
~~~

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

How do you access values in a HashMap in Java?

A

```java
int mathScore = scores.get(“Math”);
System.out.println(mathScore);
~~~

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

How do you remove a key-value pair from a HashMap in Java?

A

```java
scores.remove(“Math”);
~~~

17
Q

How do you create a Set or HashSet and add elements in Java?

A

```java
HashSet<String> cities = new HashSet<>();
cities.add("Nairobi");
cities.add("Lagos");
~~~</String>

18
Q

How do you access elements in a HashSet in Java?

A

```java
for(String city : cities) {
System.out.println(city);
}
~~~

19
Q

How do you remove an element from a HashSet in Java?

A

```java
cities.remove(“Lagos”);
~~~