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 String concat(String str) {
62 String newstr=new String();
63 newstr.count=this.count+str.count;
64 char charstr[]=new char[newstr.count];
67 for(int i=0;i<count;i++) {
68 charstr[i]=value[i+offset];
70 for(int i=0;i<str.count;i++) {
71 charstr[i+count]=str.value[i+str.offset];
76 public int lastindexOf(int ch, int fromIndex) {
77 for(int i=fromIndex;i>0;i--)
78 if (this.charAt(i)==ch)
83 public String replace(char oldch, char newch) {
84 char[] buffer=new char[count];
85 for(int i=0;i<count;i++) {
91 return new String(buffer);
94 public int indexOf(int ch) {
95 return this.indexOf(ch, 0);
98 public int indexOf(int ch, int fromIndex) {
99 for(int i=fromIndex;i<count;i++)
100 if (this.charAt(i)==ch)
105 public int indexOf(String str) {
106 return this.indexOf(str, 0);
109 public int indexOf(String str, int fromIndex) {
112 for(int i=fromIndex;i<=(count-str.count);i++)
113 if (regionMatches(i, str, 0, str.count))
118 public boolean startsWith(String str) {
119 return regionMatches(0, str, 0, str.count);
122 public boolean regionMatches(int toffset, String other, int ooffset, int len) {
123 if (toffset<0 || ooffset <0 || (toffset+len)>count || (ooffset+len)>other.count)
125 for(int i=0;i<len;i++)
126 if (other.value[i+other.offset+ooffset]!=
127 this.value[i+this.offset+toffset])
132 public char[] toCharArray() {
133 char str[]=new char[count];
134 for(int i=0;i<count;i++)
135 str[i]=value[i+offset];
139 public byte[] getBytes() {
140 byte str[]=new byte[count];
141 for(int i=0;i<count;i++)
142 str[i]=(byte)value[i+offset];
146 public int length() {
150 public char charAt(int i) {
151 return value[i+offset];
154 public String toString() {
158 public static String valueOf(Object o) {
165 public static String valueOf(int x) {
179 chararray=new char[length+1];
181 chararray=new char[length];
191 chararray[--length+voffset]=(char)(x%10+'0');
194 return new String(chararray);
197 public int hashCode() {
198 if (cachedHashcode!=0)
199 return cachedHashcode;
201 for(int i=0;i<count;i++)
202 hashcode=hashcode*31+value[i+offset];
203 cachedHashcode=hashcode;
207 public boolean equals(Object o) {
208 if (o.getType()!=getType())
213 for(int i=0;i<count;i++) {
214 if (s.value[i+s.offset]!=value[i+offset])