개발공부/Java

(6) 주요 APIⅡ(String, System, Wrapper)

klyhyeon 2020. 7. 8. 16:32
728x90

1. Java 주요 APIⅡ


 1) String: charAt, substring, trim, split 등 
  > cf. Integer.PaseInt(): 
  > det. split(주소지), trim(로그인 시 ID 검수)

 2) StringBuilder: 메모리 할당면에서 String를 overwhelm
  - 사용법: 객체로 설정한 뒤 참조값을 활용한다.
   > ex. StringBuilder sb = new StringBuilder();
   > det. 연산속도가 String보다 600배 정도 빠르다. 

 3) System.currentTImeMillis();
  - 지금 시간과 1970.1.1으로부터 차이를 초*1000배 단위인 milliseconds까지 나타내주는 함수  
   > ex. 

public Class System {
	public static void main(String[] args){

		long start = System.currentTimeMillis();  
        
        for(int i = 0; i < 100; i++) { 
  				total += i; 
			} 
   		
        long end = System.currentTimeMillis(); 

	}
   
}

     end - start로 소요시간을 나타내줄 수 있다. (출력 시 0.001 곱해야 초로 나옴)

 4) Wrapper
  - 기본 데이터 타입들을 자동 Boxing 해주는 메서드
   > ex. 
Integer x1 = a; Boolean x2 = b;
      (UnBoxing) int i = x1; Boolean j = x2;