title: Setting and fetching a StringSet from SharedPreferences?
body: <p>I am building an Android Application. I want to store a set of strings in the Preferences to order to track who used the application based on their log in information.</p>
  <p>I don't want to use a database so I know that I should use SharedPreferences to store a list of people who logged in. I want to be able to reset this list so keeping the individual log in data as Strings and NOT as StringSets is not an option. Using individual Strings means that I'll have to keep another list of those strings just so I can clean them up when I want to. A StringSet is easier to maintain.</p>
  <p>Here's what I did thus far:</p>
  <pre><code>    //this is my preferences variable
      SharedPreferences prefs = getSharedPreferences(&quot;packageName&quot;, MODE_PRIVATE);
  
      //I create a StringSet then add elements to it
      Set&lt;String&gt; set = new HashSet&lt;String&gt;();
      
      set.add(&quot;test 1&quot;);
      set.add(&quot;test 2&quot;);
      set.add(&quot;test 3&quot;);
  
      //I edit the prefs and add my string set and label it as &quot;List&quot;
      prefs.edit().putStringSet(&quot;List&quot;, set);
  
      //I commit the edit I made
      prefs.edit().commit();
  
      //I create another Set, then I fetch List from my prefs file
      Set&lt;String&gt; fetch = prefs.getStringSet(&quot;List&quot;, null);
  
      //I then convert it to an Array List and try to see if I got the values 
      List&lt;String&gt; list = new ArrayList&lt;String&gt;(fetch);
  
      for(int i = 0 ; i &lt; list.size() ; i++){
          Log.d(&quot;fetching values&quot;, &quot;fetch value &quot; + list.get(i));
      }
  </code></pre>
  <p>However, it turns out that the <code>Set&lt;String&gt; fetch</code> was null and I'm having a null pointer exception and it's probably because I wasn't storing or fetching my StringSet properly.</p>