3일차
//charAt()
String test = "012 456";
char value1 = test.charAt(2);
char value2 = test.charAt(3); value1 = "2"substring() 메소드는 주어진 인덱스에서 문자열을 추출
substring(int beginIndex) : 인덱스부터 인덱스끝까지의 문자열을 추출
substring(int beginIndex, int endIndex) : 인덱스와 인덱스 사이의 문자열을 추출
//substring()
String test = "01234-6789";
String value1 = test.substring(6);
String value2 = test.substring(0,5);
value1 = "6789"
value2 = "01234-" 가 추출된다
replace() 메소드는 첫 번째 매개값인 문자열을 찾아 두 번째 매개값인 문자열로 대치한 새로운 문자열을 생성하고 리턴
//replace()
String test = "자바 프로그래밍";
String value1 = test.replace("자바", "JAVA");
String value2 = test.replace("프로", "PRO");
String value3 = test.replace("자바", "JAVA").replace("프로", "PRO");
value1 = "JAVA 프로그래밍"
value2 = "자바 PRO그래밍"
value3 = "JAVA PRO그래밍" 가 추출된다
String 객체의 문자열은 변경이 불가능한 특성을 갖기 때문에 replace( ) 메소드가 리턴하는 문자열은 원래 문자열의 수정본이 아니라 완전히 새로운 문자열이다.
여러문자를 바꾸고 싶으면 test.replace().replace().replace()