-1

I am trying to modify the following code:

dictName = sharedPreferences.getString(PREFERENCES_DICT_NAME, null);
if (dictName == null) {
} 

My situation is I know dictName is not null and its value is "something". So I modified the code into:

dictName = sharedPreferences.getString(PREFERENCES_DICT_NAME, null);
if (dictName == "something") {
} 

However, I can't get my code work. So I am wondering is it correct for me to put dictName =="something"?

zfc
  • 11
  • 2

2 Answers2

4

You should use String.equals("something") or String.equalsIgnoreCase("something") This will do the thing and it will be fast.

Niko
  • 1,367
  • 1
  • 13
  • 37
Levente Kurusa
  • 1,858
  • 14
  • 18
0

Use this

SharedPreferences sharedPreferences = getPreferences(MODE_PRIVATE);
    SharedPreferences.Editor editor = sharedPreferences.edit();
    editor.putString(key, value);
    editor.commit();
Hybrid Developer
  • 2,320
  • 1
  • 34
  • 55