我正在检索地址表GeoCoder
GoogleMapApi并在将结果提交给Spinner
对象之前,我需要从列表中删除所有空条目。从ArrayList中删除空条目
我尝试以下两种方法,但他们都不做任何区别:
locs.removeAll(Arrays.asList("", null));
locs.removeAll(Collections.singleton(null));
-
private List<Address> getAddress(double latitude, double longitude,int maxResults) {
Geocoder gCoder = new Geocoder(getApplicationContext(),Locale.getDefault());
try {
locs = gCoder.getFromLocation(latitude, longitude, maxResults);
locs.removeAll(Arrays.asList("", null));
//locs.removeAll(Collections.singleton(null));
} catch (IOException e) {
e.printStackTrace();
}
return locs;
}
我认为第二种方式当然应该起作用。你有没有单独的列表尝试它? –