# Java program to find the sublist in a list within range ### Java program to find sublist in a list :

In this tutorial, we will learn how to find one sublist of a list within a range. The user will enter the starting index and end index of the list. We will print out the sublist using this starting and ending index. Let’s take a look at the Java program first :

### Java program to find sublist in a list :

``````import java.util.*;

public class Main {

public static void main(String[] args) {
//1
Scanner scanner = new Scanner(System.in);

//2
ArrayList numberList = new ArrayList();

//3
for (int i = 0; i <= 100; i++) {
}

//4
System.out.println("Enter starting index between 0 and 101 : ");
int start = scanner.nextInt();

//5
System.out.println("Enter second index between 0 and 101 : ");
int end = scanner.nextInt();

//6
List subList = numberList.subList(start,end);

//7
System.out.println("Sublist : "+subList.toString());

}

}``````

### Explanation :

The commented numbers in the above program denote the step number below :

1. Create one Scanner object to get the inputs from the user.
2. Create one ArrayList.
3. Using one for loop, add elements from 0 to 100 to this arraylist. So, on position i, the value is i for i = 0…100.
4. Ask the user to enter starting index for the sublist. Save it to the variable start.
5. Ask the user to enter ending index for the sublist. Save it to the variable end.
6. Create one sublist by using the subList(startIndex,endIndex) function. Starting index is start and ending index is end.
7. Print out the sublist to the user.

### Sample Output :

``````1
Enter second index between 0 and 101 :
14
Sublist : [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]

Enter starting index between 0 and 101 :
1
Enter second index between 0 and 101 :
13
Sublist : [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]``````
{"ft_lang_label":"__label__en","ft_lang_prob":0.73940945,"math_prob":0.80045587,"size":2087,"snap":"2020-24-2020-29","text_gpt3_token_len":556,"char_repetition_ratio":0.13586174,"word_repetition_ratio":0.17493473,"special_character_ratio":0.3042645,"punctuation_ratio":0.19026549,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.98348385,"pos_list":[0,1,2],"im_url_duplicate_count":[null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2020-07-04T01:52:12Z\",\"WARC-Record-ID\":\"<urn:uuid:4ce76c9b-0f08-4dbc-ad8d-f2825d9158dd>\",\"Content-Length\":\"119243\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:8a5ca688-3e6a-4221-97f7-45dd764e97b2>\",\"WARC-Concurrent-To\":\"<urn:uuid:41fa6659-a6ff-497a-a74a-13b2f303b636>\",\"WARC-IP-Address\":\"3.234.104.255\",\"WARC-Target-URI\":\"https://www.codevscolor.com/java-program-to-find-the-sublist/\",\"WARC-Payload-Digest\":\"sha1:2NG7GSZR2ISBWFAJ63UHC6JRDBOFEWEE\",\"WARC-Block-Digest\":\"sha1:YFFVSLUK6H352HWFAZXPISND6SIO7UKX\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2020/CC-MAIN-2020-29/CC-MAIN-2020-29_segments_1593655883961.50_warc_CC-MAIN-20200704011041-20200704041041-00217.warc.gz\"}"}