I want to split the input string by "\n", here is my code:
import java.util.ArrayList;
import java.util.Scanner;
public class toy_interpreter {
    public static String program;
    public static void getToyProgram() {
        Scanner prog1 = new Scanner(System.in);
        System.out.println("Please enter the toy program");
        program = prog1.nextLine();
    }
    public static String[] splitList() {
        return program.split("\n");
    }
    public static void main(String[] args) {
        getToyProgram();
        String[] parts = splitList();
        String part1 = parts[1];
        System.out.println(part1);      
    }
}
But the output shows that: Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1 at toy_interpreter.main(toy_interpreter.java:36)
could you help me?
 
     
     
    