public class StringEX0502_2 {
public static void main(String[] args) {
String a = new String(" C#");
String b = new String(",C++");
System.out.println(a+"의 길이는 "+ a.length());
System.out.println(a.contains("#")); //문자열의 포함관계 boolean
a = a.concat(b); //문자열 연결
System.out.println(a);
a = a.trim(); //문자열 앞뒤 공백 제거
System.out.println(a);
a = a.replace("C#","JAVA");
System.out.println(a);
String s[] = a.split(",");
for(int i=0; i<s.length; s++){
System.out.println("분리된 문자열 "+ i + ":"+ s[i]);
}
a = a.substring(5); //인덱스 5부터 끝까지 서브스트링 리턴
System.out.println(a);
char c = a.charAt(2); //인덱스 2의 문자 리턴
System.out.println(c);
}
}
'자바 > 기초를 자바' 카테고리의 다른 글
알고리즘이란? (0) | 2022.12.01 |
---|---|
JAVA 제어자 (0) | 2022.05.09 |
get()과 set() (0) | 2022.05.05 |
[JAVA] BufferedReader, BufferedWriter 란 무엇인가 (0) | 2022.05.03 |