Home > other >  Why SharedPreferences dont have isEmpty Method?
Why SharedPreferences dont have isEmpty Method?

Time:12-20

I want to check if sharedpref contains any keys without specifying what key it contains but it does not have any method isEmpty.

Map<String, ?> entries = sharedPreferences.getAll(); Set<String> keys = entries.keySet();

if (!keys.isEmpty()) {}

I was able to find a solution but is there a shorter solution? And why isEmpty method is not available?

CodePudding user response:

I was able to find a solution but is there a shorter solution?

entries.isEmpty(), because Map has isEmpty().

  • Related