title: Update a single variable of a class in an ArrayList of class in java
body: <p>I have a class Components:</p>
  
  <pre><code>public class Components {
  
      int numberOfNets; 
      String nameOfComp;
      String nameOfCompPart;
      int numOfPin;
  
      public components(int i, String compName, String partName, int pin) {
          this.numberOfNets = i;
          this.nameOfComp = compName;
          this.nameOfCompPart = partName; 
          this.numOfPin = pin;
      }
  
  }
  </code></pre>
  
  <p>Inside another class I created an arraylist of Components class:</p>
  
  <pre><code>List&lt;Components&gt; compList = new ArrayList&lt;Components&gt;();
  </code></pre>
  
  <p>Later in the code, I am adding the elements in List in this way:</p>
  
  <pre><code>compList.add(new Components(0,compName,partName,0));
  </code></pre>
  
  <p>See, here <code>numberOfNets</code> and <code>numOfPin</code> variables in Components class are initiated with 0 values. But these values are getting calculated/incremented in a later part of code and hence I need to update the new values of only these two variables in each list element. Now from <a href="http://docs.oracle.com/javase/6/docs/api/java/util/ArrayList.html" rel="nofollow">ArrayList doc</a> I get the idea of updating a list element using its index by <code>set</code> operation. But I am confused how to set/update a particular variable of a class in an ArrayList of a class. I need to update only these two mentioned variables, not all of the four variables in Components class. Is there any way to do that?</p>