how to find the length of a set? [closed]

2020-03-01 18:23发布

I'm trying to find the lentgh of a set from a preference. I tired set.length, but it doesnt work. Anyone know another way to find a length of a set?

   set = prefs.getStringSet("key", null);
            int X = set.length; //it doesn't like length....

标签: java android set
2条回答
Anthone
2楼-- · 2020-03-01 19:14

I believe instead of set.length, you'll want to call set.size()

查看更多
祖国的老花朵
3楼-- · 2020-03-01 19:23

Your set is a Set<String>, not a String[]. So you have to call:

int x = set.size();
查看更多
登录 后发表回答