title: How to change the value of a user within an array list whilst using an if statement?
body: <p>So I am stuck on one final part of my assignment, I have created two array lists. One is an array list that lists all users within the user group and the other lists only the administrators within that user group. I have been asked to change the value of the last administrator within the second array list and set their userType to a user instead of an administrator. I've tried using an if statement to do this but I'm not too sure on how I would structure it. I will post what I have tried up to date:</p>
  
  <p><strong>Mian class</strong></p>
  
  <pre><code>package test;
  
  public class Main{
       public static void main(String[] args) {
  
          UserGroup2 userGroupObject2 = new UserGroup2();
  
          //Once method is complete, should be called here.
          }
  
           }
           }
  </code></pre>
  
  <p><strong>UserGroup2 class</strong></p>
  
  <pre><code>    package main;
      import java.util.ArrayList;
      import java.util.Iterator;
  
  
  
      public class UserGroup2 {
  
      private ArrayList&lt;User&gt; administrators = new ArrayList&lt;&gt;();
  
      public UserGroup2() {
        addUser(new User("hpf1g17", "Admin", "Harry"));
        addUser(new User("bdh1285", "Admin", "Bob"));
      }
  
      public void addUser(User inUser) {
        this.administrators.add(inUser);
      }
  
      public ArrayList&lt;User&gt; getUserIterator() {
          return administrators;
      }
  
  //This is what I have tried so far but isn't workng
      public void setUserType()  {
          Iterator&lt;User&gt; it = administrators.iterator();    
          while (it.hasNext()) {
              User xxx = it.next();
  
              if (xxx.getUsername().equals("bdh1285")) {
  
                 xxx.UserType = "Student";
              }
          }
      }
      }     
  </code></pre>
  
  <p><strong>User class</strong>  </p>
  
  <pre><code>package main;
  
  public class User {
  
    private String username;
    private String userType;
    private String name;
  
    User(String username, String userType, String name) {
      this.username = username;
      this.userType = userType;
      this.name = name;
    }
  
    public String getUsername() {
      return username;
    }
  
    public String getUserType() {
      return userType;
    }
  
    public String getName() {
      return name;
    }
  
  
    public String setUserType(String admin) {
      return userType = admin;
    }
  
    @Override
    public String toString() {
      return username + " " + userType;
    }    
  }  
  </code></pre>
  
  <p>Any help is appreciated.</p>