//StringBuffer :메모리 절약 , string보다 빠르다.
public class Str01 {
public static void main(String[] args) {
StringBuilder s1 =new StringBuilder("Test");
StringBuilder s2 =new StringBuilder("ABCD");
s1.append(s2); //추가
System.out.println(s1);
System.out.println(s2);
s1.append(10); //추가
System.out.println(s1);
String s3 =new String("1234");
StringBuffer s4 = new StringBuffer(s3);
System.out.println(s4);
//Method and Description
//StringBuffer 자동적으로 공간을 할당받는다.
StringBuffer k1 =new StringBuffer(); //()만 입력하는경우
// -> 기본적으로 16 문자열을 만들어준다.
// -> 기본적으로 16 문자열을 만들어준다.
System.out.println(k1.length()); //()=사용된 공간X
System.out.println(k1.capacity()); //16 문자열 갯수 공간 을 할당받았다.
k1.insert(0,"ABCD"); //0번지부터"ABCD"를 넣어라
System.out.println(k1.length()); // k1.insert->4 문자열 갯수 출력
System.out.println(k1.capacity()); // 16 문자열 갯수 공간 을 할당받았다.
k1.insert(0,"12345678901123344"); // 0번지부터"12345678901123344"를 넣어라
System.out.println(k1.length()); // k1.insert->사용된 문자열 갯수 출력
System.out.println(k1.capacity()); // 34 문자열 갯수 공간 (자동확장)
//정의와 실제 사용이 다른경우
StringBuffer k2 =new StringBuffer(5); //5개로 정의함
k2.append("123456"); //실재로는 6개를
System.out.println(k2.length());
System.out.println(k2.capacity()); //6개의 배수 형태로 추가 할당함
//문자열로
StringBuffer k3 =new StringBuffer("ABCD");
System.out.println(k3.length());
System.out.println(k3.capacity()); //6개의 배수 형태로 추가 할당함
//객체로
StringBuffer k4 =new StringBuffer(new String("xyz"));
//추후 사용할 필요가없을 경우 참조변수없이 바로 값저장
//추후 사용할 필요가없을 경우 참조변수없이 바로 값저장
System.out.println(k4.length());
System.out.println(k4.capacity());
k4.append(10.7);
System.out.println(k4);
System.out.println(k4.charAt(2));
System.out.println(k4.indexOf("10"));
k4.insert(4,"_add_"); //원하는 위치에 삽입
System.out.println(k4);
System.out.println(k4.toString());
k4.reverse(); //반대로
System.out.println(k4);
k4.setLength(5); //강제로 사이즈 조절
System.out.println(k4);
System.out.println(k4.substring(2)); //지정한 위치 "이후"로만 출력
System.out.println(k4); //값 자체를 바꾼 것은 아니다.
System.out.println(k4.substring(2,4)); //지정한 위치 출력
StringBuffer k5 =new StringBuffer(" 12345 7");//저장은 공백까지 된다.
System.out.println(k5);
//System.out.println(k5.trimToSize());//->void:리턴값이 없다.(도움말확인)
k5.trimToSize();
System.out.println(k5); //뒤에가 짜리나? 글쎄? 확인 필요
StringBuffer str1= new StringBuffer("Hello, JAVA");
StringBuffer str2= new StringBuffer("안녕하세요, 자바");
System.out.println("버퍼1 내용 :"+str1);
System.out.println("버퍼1 크기 :"+str1.length());
System.out.println("버퍼1 용량 :"+str1.capacity());
System.out.println("버퍼2 내용 :"+str2);
System.out.println("버퍼2 크기 :"+str2.length());
System.out.println("버퍼2 용량 :"+str2.capacity());
//비교
String st1 = "새 천년 ";
String st2 = "대한 민국";
st1 = st1 + st2;
System.out.println(st1);
//=상동
StringBuffer st3 = new StringBuffer("새 천년 ");
st3.append("대한 민국");
System.out.println(s3);
}
}
- Open in Google Docs Viewer
- Open link in new tab
- Open link in new window
- Open link in new incognito window
- Download file
- Copy link address
- Edit PDF File on PDFescape.com
element
| Font | |
|---|---|
| font-family | |
| font-size | |
| font-style | |
| font-variant | |
| font-weight | |
| letter-spacing | |
| line-height | |
| text-decoration | |
| text-align | |
| text-indent | |
| text-transform | |
| white-space | |
| word-spacing | |
| color | |
| Background | |
| bg-attachment | |
| bg-color | |
| bg-image | |
| bg-position | |
| bg-repeat | |
| Box | |
| width | |
| height | |
| border-top | |
| border-right | |
| border-bottom | |
| border-left | |
| margin | |
| padding | |
| max-height | |
| min-height | |
| max-width | |
| min-width | |
| outline-color | |
| outline-style | |
| outline-width | |
| Positioning | |
| position | |
| top | |
| bottom | |
| right | |
| left | |
| float | |
| display | |
| clear | |
| z-index | |
| List | |
| list-style-image | |
| list-style-type | |
| list-style-position | |
| Table | |
| vertical-align | |
| border-collapse | |
| border-spacing | |
| caption-side | |
| empty-cells | |
| table-layout | |
| Effects | |
| text-shadow | |
| -webkit-box-shadow | |
| border-radius | |
| Other | |
| overflow | |
| cursor | |
| visibility |
