-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathSublistinList.java
49 lines (39 loc) · 980 Bytes
/
SublistinList.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
46
47
48
49
// Java Program to find
// Sublist in a List
import java.util.*;
public class SublistinList {
// Main Method
public static void main(String[] args) throws Exception
{
// Try block for exception
try {
ArrayList<Integer>
arrlist = new ArrayList<Integer>();
// Populating arrlist1
arrlist.add(1);
arrlist.add(4);
arrlist.add(9);
arrlist.add(25);
arrlist.add(36);
// Print arrlist
System.out.println("Original arrlist: "
+ arrlist);
// Getting the subList
// using subList() method
List<Integer> arrlist2 = arrlist.subList(2, 4);
// Print the subList
System.out.println("Sublist of arrlist: "
+ arrlist2);
}
// Catch block for exception
catch (IndexOutOfBoundsException e)
{
System.out.println("Exception thrown : " + e);
}
// Catch block for exception
catch (IllegalArgumentException e)
{
System.out.println("Exception thrown : " + e);
}
}
}