-
Notifications
You must be signed in to change notification settings - Fork 0
/
qb214.java
32 lines (26 loc) · 898 Bytes
/
qb214.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
/* QB 214
Write a Java program to copy one array list into another. & sort the second arraylist &
search an element in a array list
*/
import java.util.*;
class QB214 {
public static void main(String[] args) {
ArrayList<Integer> a1 = new ArrayList<>();
a1.add(5);
a1.add(2);
a1.add(8);
a1.add(1);
a1.add(9);
ArrayList<Integer> b1 = new ArrayList<>(a1);
Collections.sort(b1);
System.out.println("Sorted ArrayList: " + b1);
// Search for an element in the ArrayList
Scanner sc = new Scanner(System.in);
int search = sc.nextInt();
if (b1.contains(search)) {
System.out.println("Element " + search + " found in the destination ArrayList.");
} else {
System.out.println("Element " + search + " not found in the destination ArrayList.");
}
}
}