You want to use the Set
, and since it isn't an array, the square brackets ([]
)are cannot be used to access indexes.
To easily read the values from the Set
,use the enhanced for loop:
for (String str: a){
Log.d("salida", str);
}
If you want to remove items from that Set as you loop through, you will have to use an Iterator
, as shown in this answer.
Alternatively, if you want an array, you can use Set#toArray()
:
String [] prefStrings = a.toArray(new String[a.size()]);
Then you can use the square brackets (prefStrings[position]
) to access an index.