Here is a simple java code that I wrote:
List<Integer> list = new ArrayList<>();
list.add(0);
list.get(0) = 2; // Trying to set first list element's value to 2
The third line gives me an error, it says:
java: unexpected type
required: variable
found: value
Does anyone know why I am getting this type of error?
set() method is used to set the element in the particular index
List<Integer> list = new ArrayList<>();
list.add(0);
list.set(0, 2);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With