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 int indexOf(int ch) {
69 return this.indexOf(ch, 0);
72 public int indexOf(int ch, int fromIndex) {
73 for(int i=fromIndex;i<count;i++)
74 if (this.charAt(i)==ch)
79 public int indexOf(String str) {
80 return this.indexOf(str, 0);
83 public int indexOf(String str, int fromIndex) {
86 for(int i=fromIndex;i<=(count-str.count);i++)
87 if (regionMatches(i, str, 0, str.count))
92 public boolean startsWith(String str) {
93 return regionMatches(0, str, 0, str.count);
96 public boolean regionMatches(int toffset, String other, int ooffset, int len) {
97 if (toffset<0 || ooffset <0 || (toffset+len)>count || (ooffset+len)>other.count)
99 for(int i=0;i<len;i++)
100 if (other.value[i+other.offset+ooffset]!=
101 this.value[i+this.offset+toffset])
106 public char[] toCharArray() {
107 char str[]=new char[count];
108 for(int i=0;i<count;i++)
109 str[i]=value[i+offset];
113 public byte[] getBytes() {
114 byte str[]=new byte[count];
115 for(int i=0;i<count;i++)
116 str[i]=(byte)value[i+offset];
120 public int length() {
124 public char charAt(int i) {
125 return value[i+offset];
128 public String toString() {
132 public static String valueOf(Object o) {
136 public static String valueOf(int x) {
150 chararray=new char[length+1];
152 chararray=new char[length];
162 chararray[--length+voffset]=(char)(x%10+'0');
165 return new String(chararray);
168 public int hashCode() {
169 if (cachedHashcode!=0)
170 return cachedHashcode;
172 for(int i=0;i<count;i++)
173 hashcode=hashcode*31+value[i+offset];
174 cachedHashcode=hashcode;
178 public boolean equals(Object o) {
179 if (o.getType()!=getType())
184 for(int i=0;i<count;i++) {
185 if (s.value[i+s.offset]!=value[i+offset])