2013-10-24 2 views
0

GeoCoderGoogleMapApi의 주소 양식을 검색하고 그 결과를 Spinner 개체 앞에 전달하기 전에 목록에서 모든 null 항목을 제거해야합니다.ArrayList에서 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; 

} 
+1

제 생각에는 확실히 작동해야합니다. 별도의 목록으로 시도 했습니까? –

답변

0

을보십시오이 코드 목록을 반복 -

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

가 :

나는 두 가지 방법으로 다음하지만 그들 중 누구도 어떤 차이를 만드는되지 않습니다 시도
List locs = new ArrayList(); 
    locs.add(""); 
    locs.removeAll(Arrays.asList("", null)); 
    System.out.println(locs.size()); 
출력

0 

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

출력

1 

차분

0

그냥

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

for(int i=0;i<list.size();i++) { if(list.get(i)==null||list.get(i).equals(""))// in case of string only otherwise only one 체가 ck이면 충분합니다. { list.remove (i); i--; } }}