728x90
반응형
append
public class Main {
public static void main(String[] args) {
// append
StringBuffer sb = new StringBuffer();
sb.append("hello");
sb.append(" ");
sb.append("Jump to Java");
String result = sb.toString();
System.out.println(result);
}
}
**
public class Main {
public static void main(String[] args) {
String result = "";
result += "hello";
result += " ";
result += "jump to java";
System.out.println(result);
}
}
StringBuilder, StringBuffer
public class Main {
public static void main(String[] args) {
// StringBuilder StringBuffer 비슷한 자료형
StringBuilder sb = new StringBuilder();
sb.append("hello");
sb.append(" ");
sb.append("jump to java");
String result = sb.toString();
System.out.println(result);
}
}
insert
public class Main {
public static void main(String[] args) {
// insert
StringBuffer sb = new StringBuffer();
sb.append("jump to java");
sb.insert(0, "hello ");
System.out.println(sb.toString());
}
}
substring
public class Main {
public static void main(String[] args) {
// substring
StringBuffer sb = new StringBuffer();
sb.append("Hello jump to java");
System.out.println(sb.substring(0,4));
}
}
728x90
반응형
'즐거운프로그래밍' 카테고리의 다른 글
[자바] 예제 2 : BookList.CSV 파일의 데이터를 읽어서 특정 브랜드만 골라서 새로운 파일로 저장하기 (0) | 2023.11.08 |
---|---|
[자바] 예제 1 : 패스워드 파일의 데이터를 읽고 변경 후 새로운 파일로 저장하기 (1) | 2023.11.08 |
[자바] 기본개념 학습하기(split, 문자열 포맷코드, 정렬과 공백, 소수점 표현) (0) | 2023.11.08 |
[자바] 기본개념 학습하기(replaceAll, substring, toUpperCase) (0) | 2023.11.08 |
[자바] 기본개념 학습하기(indexOf, contains, charAt) (0) | 2023.11.08 |