5 private int cachedHashcode;
10 public String(char str[]) {
11 char charstr[]=new char[str.length];
12 for(int i=0;i<str.length;i++)
15 this.count=str.length;
19 public String(byte str[]) {
20 char charstr[]=new char[str.length];
21 for(int i=0;i<str.length;i++)
22 charstr[i]=(char)str[i];
24 this.count=str.length;
28 public String(String str) {
31 this.offset=str.offset;
34 public String(StringBuffer strbuf) {
35 value=new char[strbuf.length()];
36 count=strbuf.length();
38 for(int i=0;i<count;i++)
39 value[i]=strbuf.value[i];
42 public String subString(int beginIndex, int endIndex) {
43 String str=new String();
44 if (beginIndex>this.count||endIndex>this.count||beginIndex>endIndex) {
48 str.count=endIndex-beginIndex;
49 str.offset=this.offset+beginIndex;
53 public String subString(int beginIndex) {
54 return this.subString(beginIndex, this.count);
57 public int lastindexOf(int ch) {
58 return this.lastindexOf(ch, count - 1);
61 public int lastindexOf(int ch, int fromIndex) {
62 for(int i=fromIndex;i>0;i--)
63 if (this.charAt(i)==ch)
68 public String replace(char oldch, char newch) {
69 char[] buffer=new char[count];
70 for(int i=0;i<count;i++) {
76 return new String(buffer);
79 public int indexOf(int ch) {
80 return this.indexOf(ch, 0);
83 public int indexOf(int ch, int fromIndex) {
84 for(int i=fromIndex;i<count;i++)
85 if (this.charAt(i)==ch)
90 public int indexOf(String str) {
91 return this.indexOf(str, 0);
94 public int indexOf(String str, int fromIndex) {
97 for(int i=fromIndex;i<=(count-str.count);i++)
98 if (regionMatches(i, str, 0, str.count))
103 public boolean startsWith(String str) {
104 return regionMatches(0, str, 0, str.count);
107 public boolean regionMatches(int toffset, String other, int ooffset, int len) {
108 if (toffset<0 || ooffset <0 || (toffset+len)>count || (ooffset+len)>other.count)
110 for(int i=0;i<len;i++)
111 if (other.value[i+other.offset+ooffset]!=
112 this.value[i+this.offset+toffset])
117 public char[] toCharArray() {
118 char str[]=new char[count];
119 for(int i=0;i<count;i++)
120 str[i]=value[i+offset];
124 public byte[] getBytes() {
125 byte str[]=new byte[count];
126 for(int i=0;i<count;i++)
127 str[i]=(byte)value[i+offset];
131 public int length() {
135 public char charAt(int i) {
136 return value[i+offset];
139 public String toString() {
143 public static String valueOf(Object o) {
147 public static String valueOf(int x) {
161 chararray=new char[length+1];
163 chararray=new char[length];
173 chararray[--length+voffset]=(char)(x%10+'0');
176 return new String(chararray);
179 public int hashCode() {
180 if (cachedHashcode!=0)
181 return cachedHashcode;
183 for(int i=0;i<count;i++)
184 hashcode=hashcode*31+value[i+offset];
185 cachedHashcode=hashcode;
189 public boolean equals(Object o) {
190 if (o.getType()!=getType())
195 for(int i=0;i<count;i++) {
196 if (s.value[i+s.offset]!=value[i+offset])