-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEX-5.java
45 lines (45 loc) · 1.09 KB
/
EX-5.java
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
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
public class ex5{
public static void main(String[] args){
ArrayList<String> l=new ArrayList<>();
Scanner scan=new Scanner(System.in);
System.out.println("appending");
System.out.print("enter string:");
String val=scan.nextLine();
//appending
l.add(val);
System.out.println(l);
//inserting
System.out.println("inserting");
System.out.print("enter string to insert:");
val=scan.nextLine();
System.out.print("enter index:");
int i=scan.nextInt();
l.add(i,val);
System.out.println(l);
//search
System.out.println("searching");
System.out.print("enter string to search:");
val=scan.nextLine();
System.out.println(l.contains(val));
//startswith
System.out.println("startswith");
System.out.print("enter character:");
char c=scan.next().charAt(0);
for(String str:l){
if(str.charAt(0)==c){
System.out.println(str);
}
}
//sorting ascending
System.out.println("ascending");
Collections.sort(l);
System.out.println(l);
//descending
System.out.println("descending");
Collections.sort(l,Collections.reverseOrder());
System.out.println(l);
}
}