首页 > 其他 > 详细

简单的StringBuffer实现

时间:2018-09-05 20:32:15      阅读:195      评论:0      收藏:0      [点我收藏+]
package com.letv.test.base;

import java.util.Arrays;

public class StringBuffer {
private char[] value;
private int count;

public StringBuffer() {
value = new char[16];
count = 0;
}

public StringBuffer(String str) {
value = Arrays.copyOf(str.toCharArray(), str.length() + 16);
count = str.length();
}

public synchronized StringBuffer appen(String str) {
if (count + str.length() > value.length) {
value = Arrays.copyOf(value, count + str.length() + 16);
}
System.arraycopy(str.toCharArray(), 0, value, count, str.length());
// str.getChars(0, str.length(), value, count);
count = count + str.length();
return this;
}
}

简单的StringBuffer实现

原文:https://www.cnblogs.com/dava/p/9593907.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!