일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- BOJ
- 동적계획법
- 운영체제
- activity
- 다이나믹프로그래밍
- BFS
- 분할정복
- 코딩테스트
- 트리
- component
- 코딩
- 배열
- 백준
- Android
- 프로그래머스
- 이분탐색
- 코틀린
- 문자열
- 카카오블라인드
- GIT
- 스택
- 생명주기
- 그래프
- 세그먼트트리
- 안드로이드
- 자바
- dfs
- 알고리즘
- 문자열다루기
- 완전탐색
- Today
- Total
HS_development_log
알고리즘 실용 - Wrapper 클래스 메서드 활용 본문
1. Wrapper Class란?
자바의 자료형
- 기본 타입(primitive type) : byte, char, int, float, double, long, short ... 등등
- 참조 타입(reference type) : Class, Interface 등..
이때 기본 타입인 char, int, float 등을 객체로 다루기 위해서 사용하는 클래스를 Wrapper class 라고 합니다.
기본 타입(primitive type) | 래퍼 클래스(Wrapper class) |
byte | Byte |
char | Character |
int | Integer |
float | Float |
double | Double |
boolean | Boolean |
long | Long |
shor | Short |
2. Number - Integer
- Integer.toString()
toString 메서드는 인자로 int형을 받아서 String 객체로 반환합니다.
String str = Integer.toString(3); // Integer -> String 변환
- Integer.parserInt()
parseInt 메서드는 인자로 null이 아닌 String 객체를 받아서 10진수 형태의 int형으로 변환후 반환합니다.
이때 int형으로 표현이 불가능한 경우 NumberFormatException이 발생합니다.
int a = Integer.parseInt("3"); // String -> Integer 변환
- Integer.toHexString()
toHexString 메서드는 인자로 int형 을 받아서 16진수형태의 String 객체를 반환합니다.
System.out.println(Integer.toHexString(27)); // 출력 : 1b
- Integer.MAX_VALUE, Integer.MIN_VALUE
int max = Integer.MAX_VALUE; // Integer 범위의 최댓값 2147483647
int min = Integer.MIN_VALUE; // Integer 범위의 최솟값 -2147483648
각각 Int형의 최댓값, 최솟값을 가지는 상수입니다.
Long, Double, Float 등등.. Number를 상속하는 모든 클래스는 Integer 클래스와 같은 기능의 메서드들을 가지고 있습니다.
2. Character
- Character.isDigit()
Character.isDigit 메서드는 인자로 char형의 문자를 받아서 숫자인지 판별합니다(0~9).
판별후 숫자라면 true를, 숫자가 아니라면 false를 반환합니다.
System.out.println(Character.isDigit('1')); // 출력 : true
System.out.println(Character.isDigit('a')); // 출력 : false
- Character.isLowerCase(), Character.isUpperCase()
Character.isLowerCase, Character.isUpperCase 메서드는 인자로 char형의 문자를 받아서 각각 소문자, 대문자 여부를 판별합니다. 결과에 따라 true, false를 반환합니다.
System.out.println(Character.isLowerCase('a')); // 출력 : true
System.out.println(Character.isLowerCase('A')); // 출력 : false
System.out.println(Character.isUpperCase('a')); // 출력 : false
System.out.println(Character.isUpperCase('A')); // 출력 : true
- Character.toLowerCase(), Character.toUpperCase()
Character.toLowerCase, Character.toUpperCase 메서드는 인자로 char 형의 문자를 받아서
각각 대문자 -> 소문자, 소문자 -> 대문자 로 변환해서 반환합니다.
System.out.println(Character.toLowerCase('A')); // 출력 : a
System.out.println(Character.toUpperCase('a')); // 출력 : A
'Algorithm-이론' 카테고리의 다른 글
알고리즘 실용 - String 메서드 활용 (0) | 2020.08.13 |
---|---|
자바 Collections 라이브러리의 시간 복잡도 (0) | 2020.02.01 |
가장 큰 증가하는 부분 수열(LIS) (0) | 2020.01.17 |
알고리즘 - 수학 (0) | 2020.01.15 |
세그먼트 트리(Segment Tree) / Java (0) | 2020.01.13 |