28
class StringBufferDemo {
public static void main(String args[]) {
StringBuffer sb = new StringBuffer("Hello");
System.out.println("buffer = " + sb);
System.out.println("length = " + sb.length());
System.out. println("capacity = " + sb.capacity());
} }
Dastur natijasidan ko‘rish mumkinki String-Buffer obyektida qo‘shimcha joy
ajratilgan.
S:\> java StringBufferDemo
buffer = Hello
length = 5
capacity = 21
ensureCapacity
StringBuffer obyekti yaratilgandan so‘ng yangi simvollarga joy ajratish uchun
ensureCapacity usulidan foydalanish mumkin.
setLength
Buferdagi satr uzunligini o‘rnatish uchun setLength usulidan foydalanish
mumkin. Agar obyektdagi satr uzunligidan katta qiymat berilsa, usul yangi satr
oxirini nul kodli simvol bilan to‘ldiradi.
Dostları ilə paylaş: