title: How to remove moved items from a Jlist?
body: <p>I'm trying to remove the items that I moved to my second Jlist. I've been trying to do this using two different codes, one using HashSet and the other using Arrays and For loops.</p>
  
  <p>HashSet method:</p>
  
  <pre><code>//So far my code moves the items.
  
  Set&lt;Integer&gt; keepThese = new HashSet&lt;&gt;();
  int sel[] = lstLista1.getSelectedIndices();
  for (int x : sel) {
      keepThese.add(x);
  }
  for (int i=0 ; i&lt; modelo1.getSize() ; i++) {
      if(keepThese.contains(i)) {
  
      } else {
          if(modelo2.contains(modelo1.getElementAt(i))) {
          } else {
              modelo2.addElement(modelo1.getElementAt(i));
          }
      }
  }
  </code></pre>
  
  <p>Arrays and For loops</p>
  
  <pre><code>int indices[] = lstLista1.getSelectedIndices();
  String arreglo[] = new String[indices.length];
  for (int i = 0; i &lt; indices.length; i++) {
     arreglo[i] = modelo1.getElementAt(indices[i]).toString();
  }
  for (int i = indices.length-1; i &gt;= 0; i--) {
      if(modelo2.contains(modelo1.getElementAt(indices[i]))) {
  
      } else {
          modelo1.remove(indices[i]);
      }
  }
  for (int i = 0; i &lt; modelo1.getSize(); i++) {
      if(!modelo2.contains(modelo1.getElementAt(i))) {   
          modelo2.addElement(modelo1.getElementAt(i));
      }
  }
  modelo1.removeAllElements();
  for (int i = 0; i &lt; arreglo.length; i++) {
      modelo1.addElement(arreglo[i]);
  }
  </code></pre>