Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/193.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 从ArrayList中删除空项_Java_Android_List_Arraylist_Google Maps Android Api 2 - Fatal编程技术网

Java 从ArrayList中删除空项

Java 从ArrayList中删除空项,java,android,list,arraylist,google-maps-android-api-2,Java,Android,List,Arraylist,Google Maps Android Api 2,我正在从GeoCoderGoogleMapApi检索地址,在将结果传递给Spinner对象之前,我需要从列表中删除所有空条目 我尝试了以下两种方法,但没有一种能起到任何作用: locs.removeAll(Arrays.asList("", null)); locs.removeAll(Collections.singleton(null)); - private List getAddress(双纬度、双经度、int-maxResults){ Geocoder gCoder=新的地理编码器(

我正在从
GeoCoder
GoogleMapApi检索地址,在将结果传递给
Spinner
对象之前,我需要从列表中删除所有空条目

我尝试了以下两种方法,但没有一种能起到任何作用:

locs.removeAll(Arrays.asList("", null));
locs.removeAll(Collections.singleton(null));
-

private List getAddress(双纬度、双经度、int-maxResults){
Geocoder gCoder=新的地理编码器(getApplicationContext(),Locale.getDefault());
试一试{
locs=gCoder.getFromLocation(纬度、经度、最大结果);
locs.removeAll(Arrays.asList(“,null));
//locs.removeAll(Collections.singleton(null));
}捕获(IOE异常){
e、 printStackTrace();
}
返回LOC;
}

只需使用此代码遍历列表即可

    for (int i = 0; i < locs.size(); i ++){
        if (locs.get(i) == null){
            locs.remove(i);
            i --;
        }
    }
for(int i=0;i
试试这个

    List locs = new ArrayList();
    locs.add("");
    locs.removeAll(Arrays.asList("", null));
    System.out.println(locs.size());
输出

0
1
还有这个

    locs.add("");
    locs.removeAll(Collections.singleton(null));
    System.out.println(locs.size());
输出

0
1

(inti=0;我认为第二种方法肯定会起作用。您是否使用单独的列表进行了尝试?