title: Update specific object items inside Arraylist java
body: <p>How can I update the record from my <code>Arraylist</code> object?</p>
  <p>e.g:</p>
  <pre><code>List&lt;User&gt; userList = new ArrayList&lt;User&gt;();
  
  User user = new User();
  user.setUserId(1);
  user.setUsername(&quot;user1&quot;);
  userList.add(user);
  
  User user = new User();
  user.setUserId(2);
  user.setUsername(&quot;user2&quot;);
  userList.add(user);
  
  User user = new User();
  user.setUserId(3);
  user.setUsername(&quot;user3&quot;);
  userList.add(user);
  </code></pre>
  <p>Now I want to update the specific records on my <code>ArrayList</code>. Let's say I want to update the username of user id #2.
  e.g:</p>
  <pre><code>User user = new User();
  user.setUserId(2);
  user.setUsername(&quot;new_username2&quot;);
  
  //before i want to remove or update the record on the list which contain user id #2
  userList.add(user);
  </code></pre>
  <p>Something like I want to search from the list that <code>userList.contains(2)</code> then remove or update it with the new values.</p>