■ char배열의 stream은 왜 안되는걸까?

2022. 3. 9. 19:30· 무지성 메모
728x90

Arrays.stream( char[] )를 했는데 오류가 났음..

 

이게 Array.stream()안의 parameter type은

 

static DoubleStream	stream​(double[] array)	
Returns a sequential DoubleStream with the specified array as its source.
static DoubleStream	stream​(double[] array, int startInclusive, int endExclusive)	
Returns a sequential DoubleStream with the specified range of the specified array as its source.
static IntStream	stream​(int[] array)	
Returns a sequential IntStream with the specified array as its source.
static IntStream	stream​(int[] array, int startInclusive, int endExclusive)	
Returns a sequential IntStream with the specified range of the specified array as its source.
static LongStream	stream​(long[] array)	
Returns a sequential LongStream with the specified array as its source.
static LongStream	stream​(long[] array, int startInclusive, int endExclusive)	
Returns a sequential LongStream with the specified range of the specified array as its source.
static <T> Stream<T>	stream​(T[] array)	
Returns a sequential Stream with the specified array as its source.

 

이 정도인데 stream으로 다루는 데이터의 타입들 중

자주 쓰이는 실수나 숫자형은 아예 DoubleStream, IntStream, LongStream이 존재함

 

char는 자주 안쓰이고

CharStream이라는 클래스가 존재를 하지 않아서 Arrays.stream()안의 패러미터로 넣을 수 없는 것임..

 

또 자주 쓰이는 String형은 primitive가 아니라 Reference클래스기 때문에

Arrays.stream(T[] array)의 Stream형으로 반환함

 

char형은 원시타입이라 제네릭타입 받는 방식으로 받을 수도 없고,

애초에 받는 paremeter 범위 내에 없기 때문에 불가능..

Wrapper클래스로 바꿔주거나 잠시 int형으로 바꾸던가.. 아니면

내가 풀던 문제는 String에서 toCharArray()활용해 char[]로 쪼갠거니까

String.chars() 메소드를 사용, IntStream을 땡겨와서 그걸로 문제 해결해야함

저작자표시 (새창열림)

'무지성 메모' 카테고리의 다른 글

■ Get/ post, put, delete ■ 스프링 기본 파싱 전략  (0) 2022.03.14
■ string클래스의 역순 출력 함수  (0) 2022.03.10
■ 소켓통신보다 http통신이 더 비효율적인데 왜 http통신?  (0) 2022.03.08
■ @RequestBody는 언제 붙여야 하는가 ■ @Transactional 더티체킹? ■ x-www form-urlencoded json 차이  (0) 2022.03.07
■ yaml파일이란 무엇인가..? (.yml)  (0) 2022.03.04
'무지성 메모' 카테고리의 다른 글
  • ■ Get/ post, put, delete ■ 스프링 기본 파싱 전략
  • ■ string클래스의 역순 출력 함수
  • ■ 소켓통신보다 http통신이 더 비효율적인데 왜 http통신?
  • ■ @RequestBody는 언제 붙여야 하는가 ■ @Transactional 더티체킹? ■ x-www form-urlencoded json 차이
배게
배게
백엔드배게 님의 블로그입니다.
배게
백엔드
배게
전체
오늘
어제
  • 분류 전체보기 (430)
    • 알고리즘 풀이 (338)
      • 백준 (167)
      • Codility (22)
      • 프로그래머스 (123)
      • LeetCode (2)
      • CodeForces (9)
      • SWEA (15)
    • 백엔드 (11)
    • Coding existing for (3)
    • 무지성 메모 (40)
    • Debug (30)
    • 자바 (8)

블로그 메뉴

  • 홈
  • 태그
  • 미디어로그
  • 위치로그
  • 방명록

공지사항

인기 글

태그

  • 카카오톡 txt파일 정렬
  • 카카오톡
  • hibernate
  • 카톡
  • MYSQL
  • 카톡 내보내기한 파일 정렬

최근 댓글

최근 글

hELLO · Designed By 정상우.v4.2.1
배게
■ char배열의 stream은 왜 안되는걸까?
상단으로

티스토리툴바

단축키

내 블로그

내 블로그 - 관리자 홈 전환
Q
Q
새 글 쓰기
W
W

블로그 게시글

글 수정 (권한 있는 경우)
E
E
댓글 영역으로 이동
C
C

모든 영역

이 페이지의 URL 복사
S
S
맨 위로 이동
T
T
티스토리 홈 이동
H
H
단축키 안내
Shift + /
⇧ + /

* 단축키는 한글/영문 대소문자로 이용 가능하며, 티스토리 기본 도메인에서만 동작합니다.