티스토리 뷰
백준 풀면서 궁금했던 것.
왜 Scanner는 BufferedReader보다 느린 것인가..?
어떤 원리로 돌아가는지를 모르니
왜 빠른지, 느린지도 모르고 일단 쓰고는 있었음.
궁금하니까 한 번 파본다
Scanner
https://docs.oracle.com/javase/8/docs/api/java/util/Scanner.html
Scanner (Java Platform SE 8 )
Scans the next token of the input as a float. This method will throw InputMismatchException if the next token cannot be translated into a valid float value as described below. If the translation is successful, the scanner advances past the input that match
docs.oracle.com
여그서 발췌한 내용이다.
즉, Scanner 클래스는 입력값이 들어오면 그걸 읽을 때
정규식을 사용하고,
공백 따라서 입력된 내용을 토큰 단위로 나누고,
토큰 따라서 또 변환하고...
이렇게 입력값을 처리 한댄다.
왜 오래 걸렸는지 BufferedReader 안봐도 알 것 같은데...?
그래도 보자고
BufferedReader
https://docs.oracle.com/javase/8/docs/api/java/io/BufferedReader.html
BufferedReader (Java Platform SE 8 )
Reads characters into a portion of an array. This method implements the general contract of the corresponding read method of the Reader class. As an additional convenience, it attempts to read as many characters as possible by repeatedly invoking the read
docs.oracle.com
Buffer 라는 것을 이용해서 stream을 타고 온 애들을 담고 있다가 한 번에 파팟 보낸다는 것이여
Scanner랑은 다르게 뭐 입력할 때마다 정규화니 토큰화니 나 빼고,
버퍼 풀이거나 개행문자 등장하면 그 때 처리하는 거지
훨~씬 빠르게 생겼다야
겉핥기로나마 이해 완.
'(기초)그래서 뭘 배운거야? > Java' 카테고리의 다른 글
JV-88-Long과 long은 무엇이 다른가? (0) | 2022.03.23 |
---|---|
JV-86-List는 결과값이 없을 때 []이 나온다 : isEmpty() 사용하기 (0) | 2022.01.13 |
JV-85-equals() 와 ==의 차이 (0) | 2022.01.08 |
- Total
- Today
- Yesterday
- html
- ptag
- hr tag
- 정처기
- spantag
- pretag
- ul>li
- 줄글
- usemap
- definition List
- imgtag
- tabletag
- marktag
- 긴문장
- 정보처리기사필기
- 단락태그
- 2021년2회
- 합격
- emtag
- boldtag
- 복습
- br tag
- 비전공
- 정보처리기사
- hn태그
- ol>li
- 2021년42회
- tablespan
- 93점
- 정보처리기사실기
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |