-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrayLists.java
More file actions
48 lines (32 loc) · 1.13 KB
/
ArrayLists.java
File metadata and controls
48 lines (32 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import java.util.ArrayList;
// import java.util.Collections;
import java.util.Scanner;
public class ArrayLists {
public static void main(String[] args) {
// ArrayList<String> fruits = new ArrayList<>();
// fruits.add("Mango");
// fruits.add("Apple");
// fruits.add("Watermelon");
// fruits.add("Banana");
// // fruits.remove(0);
// // fruits.set(0, "Pineapple");
// // fruits.get(0);
// // fruits.size();
// // Collections.sort(fruits);
// // for(String fruit : fruits) {
// // System.out.println(fruit);
// // }
// System.out.println(fruits);
Scanner scanner = new Scanner(System.in);
ArrayList<String> foods = new ArrayList<>();
System.out.print("Enter the number of foods you would like to store: ");
int num = scanner.nextInt();
scanner.nextLine();
for(int i = 0; i < num; i ++) {
System.out.print("Enter a food: ");
foods.add(scanner.nextLine());
}
System.out.println(foods);
scanner.close();
}
}