-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringArrayList.java
More file actions
40 lines (28 loc) · 826 Bytes
/
StringArrayList.java
File metadata and controls
40 lines (28 loc) · 826 Bytes
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
package examples;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;
public class StringArrayList {
public static void main(String[] args) {
System.out.print("Enter string - ");
Scanner sc = new Scanner(System.in);
String[] data = sc.nextLine().split(" ");
// ArrayList<String> wordList = new ArrayList<String>();
//
// for (String word : data) {
// wordList.add(word);
// }
List<String> wordList = Arrays.asList(data);
System.out.println(wordList);
ArrayList<String> revWordList = new ArrayList<String>();
for (int i = wordList.size() - 1; i >= 0; i--) {
revWordList.add(wordList.get(i));
}
System.out.println(revWordList);
Collections.sort(wordList);
System.out.println(wordList);
sc.close();
}
}