먼저 distinct()를 설명하기 전에 저는 중복된 값이 포함될 수 있는 List에 중복이 있는지 확인하고 있으면 중복된 값을 반환해줘야 하는 코드를 작성해야 했었습니다. 그래서 어떤 식으로 코드를 작성할까 방법 찾다 보니 stream()에서 제공하는 distinct() 메서드를 알게 되어서 글을 쓰게 되었습니다. distinct() 외 다른 방법으로도 코드를 작성할 수 있겠지만 저는 distinct()를 사용하여 작성하는 게 간결할 거 같았습니다. 코드 블록에 작성했었던 예제 코드를 구현해보겠습니다.List list = new ArrayList();list.add("짱구");list.add("짱구");list.add("철수");list.add("철수");list.add("맹구");list.add("철..
먼저 Iterator를 설명하기 전에 제가 DB에서 조회한 목록 중 if 조건에 만족한 목록만 가져와야 하는 코드를 작성해야 했습니다. 그래서 list를 listTemp.addAll(list) 하고 listTemp를 for문 돌려서 if 조건에 만족하지 않은 데이터를 List에서 remove 했었습니다. 근데 혹시 다른 방법으로도 작성할 수 있지 않을까 해서 찾아보니 Iterator를 사용하는 방법도 있어서 글을 쓰게 되었습니다. 첫 번째 코드 블록은 처음에 작성한 코드와 같게 작성한 예제 코드이고, 두 번째 코드 블록은 Iterator를 사용한 예제 코드입니다. 1. Iterator를 사용하지 않은 코드 블록List> list = new ArrayList>();Map map0 = new HashMap(..
StringUtils.equals()에 대해 알아보겠습니다. 먼저 equals()는 문자열을 비교하는 method입니다.java Object Class들 중에서 자주 사용하고 있는 equals() method가 있습니다. StringUtils에서도 equals() method를 사용할 수 있습니다.StringUtils.class안에 method들 중 아래와 같은 method로 선언되어있는 걸 확인해 볼 수 있습니다.public static boolean equals(final CharSequence cs1, final CharSequence cs2) { if (cs1 == cs2) { return true; } if (cs1 == null || cs2 == null) { ..
contains()에 대해 알아보겠습니다. contains()는 특정값이 포함되어있는지를 true/false으로 반환하는 메서드입니다. 먼저 아래와 같이 작성하여 특정값이 포함되어있는지를 확인할 수 있습니다.String[] strArr = {"가","나","다"};String cmprVal = "가";boolean bCheck = false;for(String a : strArr){ if(a.equals(cmprVal)){ bCheck = true; }}System.out.println(bCheck);결과 : true 두 번째부터는 contains() 메서드를 사용하여 특정값이 포함되어있는지를 확인해보겠습니다.strArr 배열에 contains()를 사용하려면 Arrays.asLi..
CollectionUtils.isEmpty()에 대해 알아보겠습니다.import org.springframework.util.CollectionUtils; CollectionUtils.isEmpty()는 java Collection(List, Map, Set)의 종류의 값들의 존재 여부를 판단하는 메서드입니다.List list = new ArrayList();Set set = new HashSet();Map map = new HashMap();boolean bListEmpty;bListEmpty = CollectionUtils.isEmpty(list);System.out.println("list : " + bListEmpty);bListEmpty = CollectionUtils.isEmpty(set);S..
isEmpty()에 대해 알아보겠습니다. isEmpty()는 String 변수의 값의 존재 여부를 판단하는 메서드입니다.String a = "";String b = null;System.out.println(a.isEmpty()); // 결과: trueSystem.out.println(b.isEmpty()); // 결과: NullPointerExceptionString.java안에 method들 중 아래와 같은 method로 선언되어 있는 걸 확인할 수 있습니다.public boolean isEmpty(){ return value.length == 0;}isEmpty()를 int 변수에 사용하게 되면 java: int cannot be dereferenced와 같은 에러 메시지를 확인할 수 있습니다..
- Total
- Today
- Yesterday
- Python
- isalpha
- bool
- function
- zip
- Method
- Lambda
- isdigit
- Lower
- find
- combinations
- counter
- index
- permutations
- for
- Upper
- operators
- Built-in Functions
- If
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |