title: Set.add() in android SharedPreferences is not working as expected
body: <p>I'm trying to get a string from SharedPreferences preference and put it back in another SharedPreferences preference.</p>
  
  <p>getString() from the first preference "test1" and add it to the second preference using putStringSet().</p>
  
  <p>sample code:</p>
  
  <pre><code>void test()
  {
      Log.v("Main", "********");
  
      final SharedPreferences test1 = context.getSharedPreferences("test1", MODE_PRIVATE);
      final SharedPreferences.Editor editor1 = test1.edit();
      editor1.clear();
      editor1.putString("sample1", "This is a test");
      editor1.apply();
  
      final SharedPreferences test2 = context.getSharedPreferences("test2", MODE_PRIVATE);
      final Set&lt;String&gt; set = new HashSet&lt;&gt;(test2.getStringSet("sample2", new HashSet&lt;String&gt;()));
  
      Log.v("Main", "set.size: " + set.size());
  
      Log.v("Main", test1.getString("sample1", null));
      set.add(new String(test1.getString("sample1", null)));
  
      Log.v("Main", "set.size: " + set.size());
  
      final SharedPreferences.Editor editor2 = test2.edit();
      editor2.clear();
      editor2.putStringSet("sample2", set);
      editor2.apply();
  }
  </code></pre>
  
  <p>running the code 3 times results in:</p>
  
  <pre><code>V/Main﹕ ********
  V/Main﹕ set.size: 0
  V/Main﹕ This is a test
  V/Main﹕ set.size: 1
  V/Main﹕ ********
  V/Main﹕ set.size: 1
  V/Main﹕ This is a test
  V/Main﹕ set.size: 1
  V/Main﹕ ********
  V/Main﹕ set.size: 1
  V/Main﹕ This is a test
  V/Main﹕ set.size: 1
  </code></pre>
  
  <p>the expected result is to have the second preference increased with each call since we are adding to the Set e.g.</p>
  
  <pre><code>V/Main﹕ ********
  V/Main﹕ set.size: 0
  V/Main﹕ This is a test
  V/Main﹕ set.size: 1
  V/Main﹕ ********
  V/Main﹕ set.size: 1
  V/Main﹕ This is a test
  V/Main﹕ set.size: 2
  V/Main﹕ ********
  V/Main﹕ set.size: 2
  V/Main﹕ This is a test
  V/Main﹕ set.size: 3
  </code></pre>
  
  <p>i have already copied the Set that is coming from the second preference via getStringSet to avoid pointing to the same object.</p>
  
  <p>The problem is with Set.add(getString()). if i use a normal string e.g. Set.add("text"), it will work. i tried to create another copy of the string e.g. set.add(new String(getString .... but this is also not working.</p>
  
  <p>I have tried as well cleaning the editor or using commit() instead of apply() without luck.</p>
  
  <p>Any help is appreciated</p>