수제녹차 2019. 9. 7. 23:45
728x90
반응형

- 객체.equals(비교대상)

 

- 클래스에서 출력하는 부분 구현

public String toString(){
	
}

 

- userInput 받는 코드 예

public String getUserInput() {
	String answer = null;
    
    System.out.print("커피에 우유와 설탕을 넣어 드릴까요? (y/n) ");
    
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    
    try {
    	answer = in.readline();
    } catch ( IOException ioe) {
    	System.err.println("IO 오류");
    }
    
    if (answer == null){
    	return "no";
    }
    
    return answer;
} 

 

- Stack 동작

push : 삽입

pop : 삭제

peek : 읽기(top이 가리키는 데이터를 읽는 작업, top 값의 변화는 없다)


- valueOf()

String 클래스의 valueOf

String.valueOf(boolean/double/float/int/long/String 등등 ) -> 괄호 안의 해당 객체를 String 객체로 변환시킨다.  

 

- Boolean 클래스의 valueOf

Boolean boolean1 = Boolean.valueOf("true");

객체를 아예 생성하지 않는다.

 

- parseBoolean

- Integer.valueOf(String) vs Integer.parseInt(String)

valueOf : new Integer로 객체 반환

parseInt는 int 기본 자료형을 반환한다.  

 

- Random 값 구하는 방법

1) java.lang.math.Random

- seed 값을 변환할 수 없기 때문에 고르게 분포하지 않는다.

2) java.util.Random

- seed값을 변환시켜 매번 새로운 난수를 추출할 수 있다.

Random rand = new Random(System.currentTimeMillis());

// 0~9까지, 10개 정수 뽑아
int first = rand.nextInt(10);

 

- 현재 시간 구하기

System.currentTimeMillis();

SimpleDateFormat dayTime = new SimpleDateFormat("yyyy-mm-dd hh:mm:ss");

String str = dayTime.format(new Date(time));

반응형