개발/JAVA

java | array type Map[] null 포함 여부 체크

AM0530 2020. 6. 16. 17:50
1
2
3
4
5
6
7
8
9
10
11
Map[]resultList = (Map[])testService.selectTable(params);
 
 
boolean isResultListCheck = Arrays.asList(resultList).subList(04).contains(null);
 
// resultList에 null이 없을 경우
// isResultListCheck 의 return값 = false 
 
// resultList = [null, null, null, null, null]일 경우
// isResultListCheck 의 return값 = true 

// subList(시작인덱스 값, 종료 인덱스값)
// array에서 null이 있는지 체크할 인덱스 범위만큼 설정하면 된다.
 
cs

* 출처 : https://stackoverflow.com/questions/4729792/detect-null-reference-in-an-array

 

Detect null reference in an array

I want to detect whether or not a subrange of an array contains the null reference. Somehow like this: public static boolean containsNull (T[] array, int fromInclusive, int toExclusive) ...

stackoverflow.com