Reading a text file of the following format:

```
line1
line2

line3
line4

```

Use case is to append the first two line into a list, the last 2 lines into another list and finally append both the list to a list of lists.

Code:

```
public static void readUI() {

    try {
        BufferedReader br = new BufferedReader(new FileReader(filePath2));
        ArrayList list = new ArrayList();
        ArrayList<ArrayList<String>> checkList = new ArrayList<>();
        String line;
        String[] splitline;
        String[] subSplit;

        //populating the first list
        while ((line = br.readLine()) != null) {
            System.out.println(line);

            if (!line.trim().isEmpty()) {
                list.add(line.trim());
            } else {
                checkList.add(list);
                list.clear();
            }

        }
        //System.out.println(checkList);
        //System.out.println(checkList.get(0));
        //System.out.println(checkList.get(1));

    } catch (IOException e) {
        System.out.println("OOPS! File could not read!");
    }

}

```

Logic explained:

Read the lines from the file keep appending it to list, when I encounter a empty line append the list to a list of lists and clear the single list.

Error:

It is getting appended to the list of lists as one single list and not 2 single lists.

Any suggestions on how to correct it?