java 8의 funtional programming을 통한 기술,


final List<Integer> number = Array.asList(1, 2, 3);

final String result = number.stream().map(String::valueOf).collect(joining(" , ");


의 경우

integer 였던 number의 리스트가 stream()의 map을 이용해 String value로 바뀌어 저장되고 collect joining 을 통해 ,가 붙여 지는 결과가 만들어진다.


즉 System.out.println(result)의 결과는

1, 2, 3이 된다.


public classExample {

public static void main (String[] args)

{

List<Integer> numbers = Arrays.asList(1,2,3,4,5,6,7,8,9);

String result = numbers.stream().map(String::valueOf).collect(Collectors.joining(" , "));

//Collectors를 추가하니 에러 없이 모두 정상 처리 되었다.

System.out.println(result);

}

}



'Programing > JAVA' 카테고리의 다른 글

JAVA 1.8 정리 (2)  (0) 2016.02.13
JAVA static 선언 try catch  (0) 2016.01.12
Netty 인코더 디코더의 아주 간단한 개념  (0) 2016.01.11
Netty  (0) 2016.01.11
This Keyword  (0) 2015.02.10
Posted by kimmayer

블로그 이미지
IT 기술들 정리, 독후감을 주로 남깁니다!
kimmayer

공지사항

Yesterday
Today
Total

달력

 « |  » 2024.3
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
31

최근에 올라온 글

최근에 달린 댓글

최근에 받은 트랙백

글 보관함