如何找到一组的长度?

use*_*261 7 java android set

我试图从偏好中找到一组的lentgh.我累了set.length,但它不起作用.任何人都知道另一种方法来找到一组长度?

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

Rah*_*hin 29

我相信而不是set.length,你会打电话 set.size()


Ter*_*rry 7

你的集合是 a Set<String>,而不是 a String[]。所以你必须打电话:

int x = set.size();
Run Code Online (Sandbox Code Playgroud)