public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while (t-->0)
{
int n=sc.nextInt();
ArrayList <Integer> arr=new ArrayList<Integer>();
for(int i=0; i<n; i++)
{
arr.add(sc.nextInt());
}
System.out.println(arr);
}
}
I already know the size of the ArrayList. I also saw other questions, but they read using the hasNext(), when the size is unknown. How do I do it this way, when the array size is previously known? I just wanted to use inbuilt functions like rotate() and hence I want to create this. But this just doesn't work. it adds nothing to the list. I even tried reading as an array and using Collections.addAll to put to a new ArrayList, but that also isn't working. When I tried to convert after reading as an array to ArrayList that is giving me other errors. I also tried reading as an integer variable and adding into the list without directly inserting. That gives me just one element inserted. I don't know why.
Edit: It was an error in inputting from my part. It's solved.