Notice
Recent Posts
Recent Comments
Link
«   2024/07   »
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
more
Archives
Today
Total
관리 메뉴

WON.dev

chapter08 : parsing 본문

JAVA/chapter02_variable_dataTaye

chapter08 : parsing

GAWON 2023. 5. 25. 15:13
package org.joonzis.ex;

public class Ex08_parsing {
	public static void main(String[] args) {
		
		/*
		 * 문자열 변환은 형 변환(casting)이 아니고, 구문 분석(parsing)이다.
		 * 
		 * 1. 문자열 > 정수(String > int)
		 * Integer.parseInt("10") > 10 > Integer는 int의 참조 자료형
		 * 
		 * 2. 문자열 > 실수(String > double)
		 * Double.parseDouble("3.14") > 3.14
		 * 
		 * 3. 정수 / 실수 > 문자열 (int/double > String)
		 * String.valueOf(10) > "10"
		 * String.valueOf(3.14) > "3.14"
		 */
		
		
		String strAge = "20";
		String strHeight = "180.5";
		
		int age = Integer.parseInt(strAge);
		double height = Double.parseDouble(strHeight);
		
		System.out.println("나이 : " + (age+1) + ", 키 : " + height + "cm");
		
		
		// 문자열의 비교는 "=="로 진행하지 않는다.
		// equals() 메소드를 이용하여 비교한다.
		
		String s1 = "aaa";
		String s2 = s1;
		String s3 = new String("aaa");
		
		if(s1 == s2) {	// true
			System.out.println("같다");
		}else {
			System.out.println("다르다");
		}
		
		if(s1 == s3) {	// false
			System.out.println("같다");
		}else {
			System.out.println("다르다");
		}
		
		if(s1.equals(s3)) { // true
			System.out.println("같다");
		}else {
			System.out.println("다르다");
		}
		
		/*
		 *  == 연산자의 경우 객체의 주소 값을 비교
		 *  .equals() 메소드의 경우 대상의 값 자체를 비교
		 *  
		 *  CBV(Call By Value) - 원시 데이터 타입(주소 값을 가지지 않는다.)
		 *  CBR(Call By Reference) - 참조 객체(클래스 등)
		 */
		
		
		
		
		
		
		
		
	}
}

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

chapter09 : escape  (0) 2023.05.25
chapter07 : castingEx  (0) 2023.05.25
chapter06 : casting  (1) 2023.05.25
chapter05 : literal  (0) 2023.05.25
chapter04 : String  (0) 2023.05.25