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 boolean endsWith(String suffix) {
43 return regionMatches(count - suffix.count, suffix, 0, suffix.count);
47 public String substring(int beginIndex) {
48 return substring(beginIndex, this.count);
51 public String subString(int beginIndex, int endIndex) {
52 return substring(beginIndex, endIndex);
55 public String substring(int beginIndex, int endIndex) {
56 String str=new String();
57 if (beginIndex>this.count||endIndex>this.count||beginIndex>endIndex) {
61 str.count=endIndex-beginIndex;
62 str.offset=this.offset+beginIndex;
66 public String subString(int beginIndex) {
67 return this.subString(beginIndex, this.count);
70 public int lastindexOf(int ch) {
71 return this.lastindexOf(ch, count - 1);
74 public static String concat2(String s1, String s2) {
76 return "null".concat(s2);
81 public String concat(String str) {
82 String newstr=new String();
83 newstr.count=this.count+str.count;
84 char charstr[]=new char[newstr.count];
87 for(int i=0;i<count;i++) {
88 charstr[i]=value[i+offset];
90 for(int i=0;i<str.count;i++) {
91 charstr[i+count]=str.value[i+str.offset];
96 public int lastindexOf(int ch, int fromIndex) {
97 for(int i=fromIndex;i>0;i--)
98 if (this.charAt(i)==ch)
103 public String replace(char oldch, char newch) {
104 char[] buffer=new char[count];
105 for(int i=0;i<count;i++) {
111 return new String(buffer);
114 public String toUpperCase() {
115 char[] buffer=new char[count];
116 for(int i=0;i<count;i++) {
118 if (x>='a'&&x<='z') {
119 x=(char) ((x-'a')+'A');
123 return new String(buffer);
126 public int indexOf(int ch) {
127 return this.indexOf(ch, 0);
130 public int indexOf(int ch, int fromIndex) {
131 for(int i=fromIndex;i<count;i++)
132 if (this.charAt(i)==ch)
137 public int indexOf(String str) {
138 return this.indexOf(str, 0);
141 public int indexOf(String str, int fromIndex) {
144 for(int i=fromIndex;i<=(count-str.count);i++)
145 if (regionMatches(i, str, 0, str.count))
150 public int lastIndexOf(String str, int fromIndex) {
151 int k=count-str.count;
155 if (regionMatches(fromIndex, str, 0, str.count))
161 public int lastIndexOf(String str) {
162 return lastIndexOf(str, count-str.count);
165 public boolean startsWith(String str) {
166 return regionMatches(0, str, 0, str.count);
169 public boolean startsWith(String str, int toffset) {
170 return regionMatches(toffset, str, 0, str.count);
173 public boolean regionMatches(int toffset, String other, int ooffset, int len) {
174 if (toffset<0 || ooffset <0 || (toffset+len)>count || (ooffset+len)>other.count)
176 for(int i=0;i<len;i++)
177 if (other.value[i+other.offset+ooffset]!=
178 this.value[i+this.offset+toffset])
183 public char[] toCharArray() {
184 char str[]=new char[count];
185 for(int i=0;i<count;i++)
186 str[i]=value[i+offset];
190 public byte[] getBytes() {
191 byte str[]=new byte[count];
192 for(int i=0;i<count;i++)
193 str[i]=(byte)value[i+offset];
197 public int length() {
201 public char charAt(int i) {
202 return value[i+offset];
205 public String toString() {
209 public static String valueOf(Object o) {
216 public static String valueOf(char c) {
217 char ar[]=new char[1];
219 return new String(ar);
222 public static String valueOf(int x) {
236 chararray=new char[length+1];
238 chararray=new char[length];
248 chararray[--length+voffset]=(char)(x%10+'0');
251 return new String(chararray);
254 public static String valueOf(long x) {
268 chararray=new char[length+1];
270 chararray=new char[length];
280 chararray[--length+voffset]=(char)(x%10+'0');
283 return new String(chararray);
286 public int hashCode() {
287 if (cachedHashcode!=0)
288 return cachedHashcode;
290 for(int i=0;i<count;i++)
291 hashcode=hashcode*31+value[i+offset];
292 cachedHashcode=hashcode;
296 public boolean equals(Object o) {
297 if (o.getType()!=getType())
302 for(int i=0;i<count;i++) {
303 if (s.value[i+s.offset]!=value[i+offset])
309 public boolean equalsIgnoreCase(String s) {
312 for(int i=0;i<count;i++) {
313 char l=s.value[i+s.offset];
314 char r=value[i+offset];
316 l=(char)((l-'a')+'A');
318 r=(char)((r-'a')+'A');