Notice
Recent Posts
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- jsp 내부객체
- jsp
- 자바
- Spring
- 마이바티스
- 셋업
- jquery
- 스프링
- jstl
- Eclipse
- 오라클
- springboot
- 자바스크립트
- SESSION
- 면접
- 설치
- 알고리즘
- EL태그
- 필터체인
- 이클립스
- Oracle
- 폼태그
- 깃허브 간단요약
- java
- 제이쿼리
- 설정
- 버튼
- html
- 깃허브
- MySQL
Archives
- Today
- Total
은은하게 코드 뿌시기
자바 JAVA 래퍼클래스 (wrapper) 본문
728x90
*기본형 변수도 어쩔수 없이 객체로 다뤄야 하는 경우에 사용
ex 기본형 값이 아닌 객체로 저장행 할때, 객체간의 비교가 필요할때
기본형 | 래퍼클래스 | 생성자 | 활용예 |
boolean | Boolean | Boolean (boolean value) Boolean (String s) |
Boolean b = new Boolean(true); Boolean b2 = new Boolean("true"); |
char | Character | Character (char value) | Character c = new Character('a'); |
byte | Byte | Byte (byte value) Byte (String s) |
Byte b = new Byte(10); Byte b2 = new Byte("10"); |
short | Short | Short (short value) Short (String s) |
Short s = new Short(10); Short s2 = new Short("10"); |
int | Integer | Integer (int value) Integer (String s) |
Integer i = new Int(100); Integer i2 = new Int("100"); |
long | Long | Long (long value) Long (String s) |
Long l = new Long(100); Long l2 = new Long("100"); |
float | Float | Float (double value) Float (float value) Float (String s) |
Float f = new Float(1.0); Float f2 = new Float(1.0f); Float f3 = new Float("1.0f"); |
double | Double | Double (double value) Double (String s) |
Double d = new Double(1.0); Double s2 = new Double("1.0"); |
래퍼 클래스들은 모드 equals()가 오버라이딩 되있어서 주소값이 아닌 객체가 가지고있는 값을 비교한다.
오토박싱이 된다고 해도 Integer객체에 비교 연산자를 사용 할 수 없다 . 대신 CompareTo()를 제공한다.
package kr.co.obj; public class WrapperEx1 { public static void main(String[] args) { Integer i = new Integer(100); Integer i2 = new Integer(100); System.out.println("i==i2 ? " + (i==i2)); System.out.println("i.equals(i2) ? " + i.equals(i2)); System.out.println("i.compareTo(i2) ? " + i.compareTo(i2)); System.out.println("i.toString()= " + i.toString()); System.out.println("MAX_VALUE="+ Integer.MAX_VALUE); System.out.println("MIN_VALUE="+ Integer.MIN_VALUE); System.out.println("SIZE="+ Integer.SIZE + "bits"); System.out.println("BYTE="+ Integer.BYTES + "bytes"); System.out.println("TYPE="+ Integer.TYPE); } } |
실행결과
i==i2 ? false i.equals(i2) ? true i.compareTo(i2) ? 0 i.toString()= 100 MAX_VALUE=2147483647 MIN_VALUE=-2147483648 SIZE=32bits BYTE=4bytes TYPE=int |
728x90
'자바 > 자바 기본' 카테고리의 다른 글
자바 JAVA FILE COPY 파일 복사/수정 간단 예제 (0) | 2022.06.17 |
---|---|
자바 JAVA ArrayList 간단 예제 및 함수 (3) | 2022.06.16 |
JAVA 자바 향상된 for문 (0) | 2022.06.15 |
자바 JAVA 접근제어자 (0) | 2022.06.15 |
자바 JAVA 정규표현식 (2) | 2022.06.15 |
Comments