ArrayList issues

Hello, coders. I don’t understand why I have this error while creating my ArrayList.
It says: “Syntax error, insert ‘Dimensions’ to complete ReferenceType”

Thanks for helping me

the required data type seems to be Integer:

// random example from the internet
ArrayList<Integer> arl = new ArrayList<Integer>();

you use int

1 Like

Thank you so much. I appreciate your help. however, now this is my unexpected result.

I was supposed to have only odd numbers, but I do not know what happens here.

I probed with my System,out.println(i) out of the if statement, but the same result.

Consider what you are printing. If what you are printing isn’t what you wanted to see, possibly you are printing the wrong thing.

You cannot use primitive data types in ArrayLists. You have to use the wrapper classes: so Integer instead of int, Long instead of long, Boolean instead of boolean, etc.

For the odd numbers, you aren’t actually checking what’s in oddNumbers. Try printing oddNumbers after the while loop.

You may want to look into the community edition of IntelliJ Idea. It is better for Java than VSCode.

1 Like

Thank you so much for your feedback

1 Like