-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArraylists.java
More file actions
21 lines (20 loc) · 830 Bytes
/
Copy pathArraylists.java
File metadata and controls
21 lines (20 loc) · 830 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import java.util.*;
public class Arraylists {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
ArrayList<String> playlist = new ArrayList<>();
System.out.print("My first song: ");
String firstSong = scanner.nextLine();
playlist.add(firstSong);
System.out.print("My second song: ");
String secondSong = scanner.nextLine();
playlist.add(secondSong);
System.out.print("My third song: ");
String thirdSong = scanner.nextLine();
playlist.add(thirdSong);
playlist.remove(1);
System.out.println("Song at index 1: " + playlist.get(1));
System.out.println("Contains Animal? " + playlist.contains("Animal"));
System.out.println("Playlist: " + playlist);
}
}