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 int indexOf(int ch) {
115 return this.indexOf(ch, 0);
118 public int indexOf(int ch, int fromIndex) {
119 for(int i=fromIndex;i<count;i++)
120 if (this.charAt(i)==ch)
125 public int indexOf(String str) {
126 return this.indexOf(str, 0);
129 public int indexOf(String str, int fromIndex) {
132 for(int i=fromIndex;i<=(count-str.count);i++)
133 if (regionMatches(i, str, 0, str.count))
138 public int lastIndexOf(String str, int fromIndex) {
139 int k=count-str.count;
143 if (regionMatches(fromIndex, str, 0, str.count))
149 public int lastIndexOf(String str) {
150 return lastIndexOf(str, count-str.count);
153 public boolean startsWith(String str) {
154 return regionMatches(0, str, 0, str.count);
157 public boolean startsWith(String str, int toffset) {
158 return regionMatches(toffset, str, 0, str.count);
161 public boolean regionMatches(int toffset, String other, int ooffset, int len) {
162 if (toffset<0 || ooffset <0 || (toffset+len)>count || (ooffset+len)>other.count)
164 for(int i=0;i<len;i++)
165 if (other.value[i+other.offset+ooffset]!=
166 this.value[i+this.offset+toffset])
171 public char[] toCharArray() {
172 char str[]=new char[count];
173 for(int i=0;i<count;i++)
174 str[i]=value[i+offset];
178 public byte[] getBytes() {
179 byte str[]=new byte[count];
180 for(int i=0;i<count;i++)
181 str[i]=(byte)value[i+offset];
185 public int length() {
189 public char charAt(int i) {
190 return value[i+offset];
193 public String toString() {
197 public static String valueOf(Object o) {
204 public static String valueOf(char c) {
205 char ar[]=new char[1];
207 return new String(ar);
210 public static String valueOf(int x) {
224 chararray=new char[length+1];
226 chararray=new char[length];
236 chararray[--length+voffset]=(char)(x%10+'0');
239 return new String(chararray);
242 public int hashCode() {
243 if (cachedHashcode!=0)
244 return cachedHashcode;
246 for(int i=0;i<count;i++)
247 hashcode=hashcode*31+value[i+offset];
248 cachedHashcode=hashcode;
252 public boolean equals(Object o) {
253 if (o.getType()!=getType())
258 for(int i=0;i<count;i++) {
259 if (s.value[i+s.offset]!=value[i+offset])
265 public boolean equalsIgnoreCase(String s) {
268 for(int i=0;i<count;i++) {
269 char l=s.value[i+s.offset];
270 char r=value[i+offset];
272 l=(char)((l-'a')+'A');
274 r=(char)((r-'a')+'A');