title: Convert list to set by ImmutableSet.copyOf() and new HashSet<>(list);
body: <p>Good day,</p>
  
  <p>I have a set that contains some data:</p>
  
  <pre><code>Set&lt; AItem &gt; aItems = aItem
                      .getItems( );
  </code></pre>
  
  <p>Because I want to do some sorting, so I convert it to list first, after sort, then only turn it back to set:</p>
  
  <pre><code>List&lt; AItem &gt; tempoAccounts = new ArrayList(aItems);
  
  Collections.sort(tempoAccounts, new Comparator() {
                  public int compare(Object arg0, Object arg1) {
                      // sorting logic here
                  }
              });
  
  // convert from list back to set
  aItems = ImmutableSet.copyOf(tempoAccounts);
  </code></pre>
  
  <p>This give me a correct result, all my data sort accordingly.</p>
  
  <p>However, If I want to add more item into <code>aItems</code>:</p>
  
  <pre><code>AItem aai = new AItem();
              aai.setAId( (long) 2222 );
              aai.setLimit( BigDecimal.ZERO );
  </code></pre>
  
  <p>then I will hit :</p>
  
  <pre><code>Exception created : [java.lang.UnsupportedOperationException
      at com.google.common.collect.ImmutableCollection.add(ImmutableCollection.java:91)
  </code></pre>
  
  <p>So I change the </p>
  
  <pre><code>aItems = ImmutableSet.copyOf(tempoAccounts);
  </code></pre>
  
  <p>to</p>
  
  <pre><code>aItems = new HashSet&lt;AItem&gt;(tempoAccounts);
  </code></pre>
  
  <p>This will not give me <code>UnsupportedOperationException</code> if I add new item inside this Set. But my sorting is gone, the Set is not sort properly.</p>
  
  <p>Any ideas to sort my Set, and then can add more item inside without exception?</p>
  
  <p>Kindly advise.</p>