why it's geting null value
this output are occurs
mother
son
cat
dog
program
car
null
father
daughter
package com.codegym.task.task07.task0720;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
/*
Shuffled just in time
*/
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
Scanner sc= new Scanner(System.in);
int n= Integer.parseInt(reader.readLine());
int m= Integer.parseInt(reader.readLine());
ArrayList<String> list= new ArrayList<>();
for(int i=0; i<n+1; i++){
list.add(reader.readLine());
// System.out.println(list.get(i));
}
for(int j=0; j<n; j++){
int n1=n-1;
String s= list.get(j);
if(m>j){
list.remove(s);
//j++;
list.add(n,s);
// System.out.println(n1);
// System.out.println(list.get(j));
}
j++;
}
for(int i=0; i<n+1; i++){
System.out.println(list.get(i));
}
//write your code here
}
}