String数据类型由一个类来定义,那么请问... 在jdk的文件夹下面有一个src.zip 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 package java.lang;import java.io.ObjectStreamClass;import java.io.ObjectStreamField;import java.io.UnsupportedEncodingException;import java.util.ArrayList;import java.util.Comparator;import java.util.Locale;import java.util.regex.Matcher;import java.util.regex.Pattern;import java.util.regex.PatternSyntaxException;public final class String implements java.io.Serializable, Comparable, CharSequence{ private char value[]; private int offset; private int count; private int hash = 0; private static final long serialVersionUID = -6849794470754667710L; private static final ObjectStreamField[] serialPersistentFields = new ObjectStreamField[0]; public String() { value = new char[0]; } public String(String original) { this.count = original.count; if (original.value.length > this.count) { this.value = new char[this.count]; System.arraycopy(original.value, original.offset, this.value, 0, this.count); } else { this.value = original.value; } } public String(char value[]) { this.count = value.length; this.value = new char[count]; System.arraycopy(value, 0, this.value, 0, count); } public String(char value[], int offset, int count) { if (offset < 0) { throw new StringIndexOutOfBoundsException(offset); } if (count < 0) { throw new StringIndexOutOfBoundsException(count); } if (offset > value.length - count) { throw new StringIndexOutOfBoundsException(offset + count); } this.value = new char[count]; this.count = count; System.arraycopy(value, offset, this.value, 0, count); } public String(byte ascii[], int hibyte, int offset, int count) { checkBounds(ascii, offset, count); char value[] = new char[count]; this.count = count; this.value = value; if (hibyte == 0) { for (int i = count ; i-- > 0 ;) { value[i] = (char) (ascii[i + offset] & 0xff); } } else { hibyte <<= 8; for (int i = count ; i-- > 0 ;) { value[i] = (char) (hibyte | (ascii[i + offset] & 0xff)); } } } public String(byte ascii[], int hibyte) { this(ascii, hibyte, 0, ascii.length); } private static void checkBounds(byte[] bytes, int offset, int length) { if (length < 0) throw new StringIndexOutOfBoundsException(length); if (offset < 0) throw new StringIndexOutOfBoundsException(offset); if (offset > bytes.length - length) throw new StringIndexOutOfBoundsException(offset + length); } public String(byte bytes[], int offset, int length, String charsetName) throws UnsupportedEncodingException { if (charsetName == null) throw new NullPointerException("charsetName"); checkBounds(bytes, offset, length); value = StringCoding.decode(charsetName, bytes, offset, length); count = value.length; } public String(byte bytes[], String charsetName) throws UnsupportedEncodingException { this(bytes, 0, bytes.length, charsetName); } public String(byte bytes[], int offset, int length) { checkBounds(bytes, offset, length); value = StringCoding.decode(bytes, offset, length); count = value.length; } public String(byte bytes[]) { this(bytes, 0, bytes.length); } public String (StringBuffer buffer) { synchronized(buffer) { buffer.setShared(); this.value = buffer.getValue(); this.offset = 0; this.count = buffer.length(); } } String(int offset, int count, char value[]) { this.value = value; this.offset = offset; this.count = count; } public char charAt(int index) { if ((index < 0) || (index >= count)) { throw new StringIndexOutOfBoundsException(index); } return value[index + offset]; } public void getChars(int srcBegin, int srcEnd, char dst[], int dstBegin) { if (srcBegin < 0) { throw new StringIndexOutOfBoundsException(srcBegin); } if (srcEnd > count) { throw new StringIndexOutOfBoundsException(srcEnd); } if (srcBegin > srcEnd) { throw new StringIndexOutOfBoundsException(srcEnd - srcBegin); } System.arraycopy(value, offset + srcBegin, dst, dstBegin, srcEnd - srcBegin); } public void getBytes(int srcBegin, int srcEnd, byte dst[], int dstBegin) { if (srcBegin < 0) { throw new StringIndexOutOfBoundsException(srcBegin); } if (srcEnd > count) { throw new StringIndexOutOfBoundsException(srcEnd); } if (srcBegin > srcEnd) { throw new StringIndexOutOfBoundsException(srcEnd - srcBegin); } int j = dstBegin; int n = offset + srcEnd; int i = offset + srcBegin; char[] val = value; /* avoid getfield opcode */ while (i < n) { dst[j++] = (byte)val[i++]; } } public byte[] getBytes(String charsetName) throws UnsupportedEncodingException { return StringCoding.encode(charsetName, value, offset, count); }太多了,拷不下来。 java.lang.String在jbuilder中search->find classes->java.lang.String jdk中就有,其实我们没有必要去研究那个,直到怎么用就可以了 java.lang.String在jbuilder中search->find classes->java.lang.String java.lang.Object是任何类的祖宗。 反编译一下java.lang中的String.class就能看到源码 楼上的各位都很强啊偶也只是好奇想要看看究竟怎么发现String类也是很复杂啊多谢 javafaq2004(又失业了) 考来的这么多偶也大概明白一些了 如果你用javareflection察看一个变量的类型的时候如果这个变量是int char byte short long float double boolean的话,它只会显示上述的名字,如果是其他的就会显示完整的类名比如java.lang.string和这些permitive变量相应的也有类,比如int->interger 线程传值,在线等!急! 请教高手2个问题! 很经典的面试题,第二次遇见了,还是没有答上来 页面传值问题!急! 请教一个打包.EXE的问题 我能否看到一个类在内存中有几个实例o0oooo00o0o0o0o0o0o0o 初学者关于java的图像显示的问题 两个关于多线程的问题,对多线程熟悉的朋友解答 谁能介绍一下java的异常处理? 集合 夜深了,送道题给赔我过夜的人们。 怎么找到上次new的线程?
import java.io.ObjectStreamField;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
public final class String
implements java.io.Serializable, Comparable, CharSequence
{
private char value[]; private int offset; private int count; private int hash = 0;
private static final long serialVersionUID = -6849794470754667710L; private static final ObjectStreamField[] serialPersistentFields =
new ObjectStreamField[0]; public String() {
value = new char[0];
}
public String(String original) {
this.count = original.count;
if (original.value.length > this.count) { this.value = new char[this.count];
System.arraycopy(original.value, original.offset,
this.value, 0, this.count);
} else { this.value = original.value;
}
}
public String(char value[]) {
this.count = value.length;
this.value = new char[count];
System.arraycopy(value, 0, this.value, 0, count);
} public String(char value[], int offset, int count) {
if (offset < 0) {
throw new StringIndexOutOfBoundsException(offset);
}
if (count < 0) {
throw new StringIndexOutOfBoundsException(count);
}
if (offset > value.length - count) {
throw new StringIndexOutOfBoundsException(offset + count);
} this.value = new char[count];
this.count = count;
System.arraycopy(value, offset, this.value, 0, count);
} public String(byte ascii[], int hibyte, int offset, int count) {
checkBounds(ascii, offset, count); char value[] = new char[count];
this.count = count;
this.value = value; if (hibyte == 0) {
for (int i = count ; i-- > 0 ;) {
value[i] = (char) (ascii[i + offset] & 0xff);
}
} else {
hibyte <<= 8;
for (int i = count ; i-- > 0 ;) {
value[i] = (char) (hibyte | (ascii[i + offset] & 0xff));
}
}
}
public String(byte ascii[], int hibyte) {
this(ascii, hibyte, 0, ascii.length);
} private static void checkBounds(byte[] bytes, int offset, int length) {
if (length < 0)
throw new StringIndexOutOfBoundsException(length);
if (offset < 0)
throw new StringIndexOutOfBoundsException(offset);
if (offset > bytes.length - length)
throw new StringIndexOutOfBoundsException(offset + length);
}
public String(byte bytes[], int offset, int length, String charsetName)
throws UnsupportedEncodingException
{
if (charsetName == null)
throw new NullPointerException("charsetName");
checkBounds(bytes, offset, length);
value = StringCoding.decode(charsetName, bytes, offset, length);
count = value.length;
}
throws UnsupportedEncodingException
{
this(bytes, 0, bytes.length, charsetName);
} public String(byte bytes[], int offset, int length) {
checkBounds(bytes, offset, length);
value = StringCoding.decode(bytes, offset, length);
count = value.length;
} public String(byte bytes[]) {
this(bytes, 0, bytes.length);
} public String (StringBuffer buffer) {
synchronized(buffer) {
buffer.setShared();
this.value = buffer.getValue();
this.offset = 0;
this.count = buffer.length();
}
} String(int offset, int count, char value[]) {
this.value = value;
this.offset = offset;
this.count = count;
} public char charAt(int index) {
if ((index < 0) || (index >= count)) {
throw new StringIndexOutOfBoundsException(index);
}
return value[index + offset];
} public void getChars(int srcBegin, int srcEnd, char dst[], int dstBegin) {
if (srcBegin < 0) {
throw new StringIndexOutOfBoundsException(srcBegin);
}
if (srcEnd > count) {
throw new StringIndexOutOfBoundsException(srcEnd);
}
if (srcBegin > srcEnd) {
throw new StringIndexOutOfBoundsException(srcEnd - srcBegin);
}
System.arraycopy(value, offset + srcBegin, dst, dstBegin,
srcEnd - srcBegin);
} public void getBytes(int srcBegin, int srcEnd, byte dst[], int dstBegin) {
if (srcBegin < 0) {
throw new StringIndexOutOfBoundsException(srcBegin);
}
if (srcEnd > count) {
throw new StringIndexOutOfBoundsException(srcEnd);
}
if (srcBegin > srcEnd) {
throw new StringIndexOutOfBoundsException(srcEnd - srcBegin);
}
int j = dstBegin;
int n = offset + srcEnd;
int i = offset + srcBegin;
char[] val = value; /* avoid getfield opcode */ while (i < n) {
dst[j++] = (byte)val[i++];
}
} public byte[] getBytes(String charsetName)
throws UnsupportedEncodingException
{
return StringCoding.encode(charsetName, value, offset, count);
}太多了,拷不下来。
在jbuilder中
search->find classes->java.lang.String
在jbuilder中
search->find classes->java.lang.String
偶也只是好奇想要看看究竟
怎么发现String类也是很复杂啊
多谢 javafaq2004(又失业了) 考来的这么多
偶也大概明白一些了
如果这个变量是int char byte short long float double boolean的话,它只会显示上述的名字,如果是其他的就会显示完整的类名比如java.lang.string
和这些permitive变量相应的也有类,比如int->interger