I have an Arraylist of integers.
My requirement is to determine if the arraylist HAS an element existing at the specified index.If YES, then a value should be set to that index (using set method), else a value should be added to that index location(using add method)
Finding it a bit difficult to handle the above condition in my java code.Please help.
Here's what I have so far:
    ArrayList<Integer> tempArray = new ArrayList<Integer>();
        int counter = 0;
        int tempValue = 0;
    For LOOP -
      if (//certain conditions are satisfied){
      tempValue = calculateNewValue();
      tempArray.add(counter, tempValue); //Need some logic here to determine if its a set or add method to be used
    }
if (//some other conditions are satisfied){
       counter++;
}
    end For LOOP
 
     
     
     
     
     
     
     
    