-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringBufferEx.java
More file actions
42 lines (30 loc) · 899 Bytes
/
Copy pathStringBufferEx.java
File metadata and controls
42 lines (30 loc) · 899 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package com.javaex.api.stringclass;
public class StringBufferEx {
public static void main(String[] args) {
// 버퍼의 생성
StringBuffer sb = new StringBuffer("This");
// 문자열 추가 : append()
sb.append(" is pensil");
// 문자열 삽입 : insert()
sb.insert(8, "my");
// 문자열 치환 : replace()
sb.replace(8, 10, "your ");
System.out.println(sb);
sb.setLength(10); // 버퍼 길이 변경
System.out.println(sb);
/*String s = new StringBuffer("This")
.append(" is")
.append(" pensil")
.insert(8, "my")
.replace(8, 10, "your ")
.toString();
*/
StringBuffer sb2 = new StringBuffer("This")
.append(" is")
.append(" pensil")
.insert(8, "my")
.replace(8, 10, "your ");
String s = sb2.toString();
System.out.println(s);
}
}