I am a beginner. Can you please help me identify the mistake in the following program ?
import java.util.*;
public class Main
{
public static void main(String[] args) {
ArrayList li = new ArrayList<>();
li.add(1);
li.add(2);
li.add(3);
System.out.println(li.get(1));
int arr[] = new int[li.size()];
for(int i=0; i<li.size(); i++)
{
arr[i] = li.get(i);
}
for(int item:arr)
System.out.println(item);
}
}
While executing the above program, I get the following error :
Main.java:23: error: incompatible types: Object cannot be converted to int
arr[i] = li.get(i);