栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

数据结构变量字符串类(JAVA)

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

数据结构变量字符串类(JAVA)

数据结构变量字符串类(JAVA)
package Chapter3;

import java.io.Serializable;

public class MyStringBuffer implements Serializable {
    private char[] value;   //字符数组,私有成员变量
    private int n;          //串长度

    
    public MyStringBuffer(int capacity){
        this.value=new char[capacity];
        this.n=0;
    }
    
    public MyStringBuffer(){
        this(16);
    }
    
    public MyStringBuffer(String s){
        this(s.length()+16);
        this.n=s.length();
        for (int i=0; i this.n){
            i=this.n;
        }
        return this.value[i];
    }
    
    public void setCharAt(int i, char ch){
        if (i < 0){
            i=0;
        }
        else if (i > this.n){
            i=this.n;
        }
        this.value[i]=ch;
    }

    
    public synchronized MyStringBuffer insert(int i, String s){
        if (this.n==0 && i==0 || this.n>0 && i>=0 && i<=this.n){
            if (s==null){
                s="";
            }
            char[] temp=this.value;
            //若数组空间不足,则扩充
            if (this.value.length =i; j--){
                this.value[j + s.length()]=temp[j];
            }
            for (int j=0; j
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/310789.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号