Setter Getter Method in Loop in Java
<p>I have recently learned about Setters and Getters. I can use them but the problem is that I have to use them in a loop. Some of the code that I am using is mentioned below.</p>

<p>I am entering Student information in a loop, and then editing it in another loop using Set Get methods. I can use the setter and getter methods without the loop but I am not sure how to use them inside the loop. So please guide me to add students in a stu array.</p>

<pre><code>    public static void   Addstudents()
    {   
      for(int i=0; i&lt;stu.length; i++)
      {
        stu[i]=new Stuinfo();
        System.out.println("Enter name ");
        name= sc.next();
        System.out.println("Enter id  ");
        id= sc.next();
      }
    }
</code></pre>

<p>And to edit the data, I want to run a loop and use the setter method to set the values. Something like this:</p>

<pre><code>  public void Modify()
  { 
    String Cid; 
    System.out.println("You r modifying account");
    for (int i=0; i&lt;stu.length;i++)
    { 
      stu[i].setId(id)...// dont know what to do in loop hree 
    }
  }
</code></pre>
