public class example
{
public ArrayList<Integer> ToFill = new ArrayList<>();
public void Alter(int Value , int Position)
{
ToFill.get(Position) = Value ; // this line has an error
}
}
For some reason this code gives compilation Error ,could anyone explain why?
ToFill.get(Position)returns a value where the left-hand side of the assignment must be a variable. Instead, useset(index, element)as follows:However, what you are doing is only valid if you are using arrays, for example:
As a side note, always use Java naming convention:
toFillinstead ofToFillalterinstead ofAlterpositioninstead ofPosition.valueinstead ofValue.