Java的string类是用什么语言编写的?
发布网友
发布时间:2022-02-28 22:30
我来回答
共2个回答
热心网友
时间:2022-02-28 23:59
jdk目录中有所有JAVA类的源代码压缩包
热心网友
时间:2022-03-01 01:17
java写的,网上查都有的,我给你部分看看
/*
* @(#)String.java 1.187 04/07/13
*
* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
* SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*/
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.Formatter;
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<String>, CharSequence
{
/** The value is used for character storage. */
private final char value[];
/** The offset is the first index of the storage that is used. */
private final int offset;
/** The count is the number of characters in the String. */
private final int count;
/** Cache the hash code for the string */
private int hash; // Default to 0
/** use serialVersionUID from JDK 1.0.2 for interoperability */
private static final long serialVersionUID = -6849794470754667710L;
private static final ObjectStreamField[] serialPersistentFields =
new ObjectStreamField[0];
public String() {
this.offset = 0;
this.count = 0;
this.value = new char[0];
}
public String(String original) {
int size = original.count;
char[] originalValue = original.value;
char[] v;
if (originalValue.length > size) {
// The array representing the String is bigger than the new
// String itself. Perhaps this constructor is being called
// in order to trim the baggage, so make a copy of the array.
v = new char[size];
System.arraycopy(originalValue, original.offset, v, 0, size);
} else {
// The array representing the String is the same
// size as the String, so no point in making a copy.
v = originalValue;
}
this.offset = 0;
this.count = size;
this.value = v;
}
public String(char value[]) {
int size = value.length;
char[] v = new char[size];
System.arraycopy(value, 0, v, 0, size);
this.offset = 0;
this.count = size;
this.value = v;
}
public String(char value[], int offset, int count) {
if (offset < 0) {
throw new StringIndexOutOfBoundsException(offset);
}
if (count < 0) {
throw new StringIndexOutOfBoundsException(count);
}
// Note: offset or count might be near -1>>>1.
if (offset > value.length - count) {
throw new StringIndexOutOfBoundsException(offset + count);
}
char[] v = new char[count];
System.arraycopy(value, offset, v, 0, count);
this.offset = 0;
this.count = count;
this.value = v;
}
public String(int[] codePoints, int offset, int count) {
if (offset < 0) {
throw new StringIndexOutOfBoundsException(offset);
}
if (count < 0) {
throw new StringIndexOutOfBoundsException(count);
}
// Note: offset or count might be near -1>>>1.
if (offset > codePoints.length - count) {
throw new StringIndexOutOfBoundsException(offset + count);
}
int expansion = 0;
int margin = 1;
char[] v = new char[count + margin];
int x = offset;
int j = 0;
for (int i = 0; i < count; i++) {
int c = codePoints[x++];
if (c < 0) {
throw new IllegalArgumentException();
}
if (margin <= 0 && (j+1) >= v.length) {
if (expansion == 0) {
expansion = (((-margin + 1) * count) << 10) / i;
expansion >>= 10;
if (expansion <= 0) {
expansion = 1;
}
} else {
expansion *= 2;
}
char[] tmp = new char[Math.min(v.length+expansion, count*2)];
margin = (tmp.length - v.length) - (count - i);
System.arraycopy(v, 0, tmp, 0, j);
v = tmp;
}
if (c < Character.MIN_SUPPLEMENTARY_CODE_POINT) {
v[j++] = (char) c;
} else if (c <= Character.MAX_CODE_POINT) {
Character.toSurrogates(c, v, j);
j += 2;
margin--;
} else {
throw new IllegalArgumentException();
}
}
this.offset = 0;
this.value = v;
this.count = j;
}
@Deprecated
public String(byte ascii[], int hibyte, int offset, int count) {
checkBounds(ascii, offset, count);
char value[] = new char[count];
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));
}
}
this.offset = 0;
this.count = count;
this.value = value;
}
public String(byte ascii[], int hibyte) {
this(ascii, hibyte, 0, ascii.length);
}
public String(byte bytes[], int offset, int length, String charsetName)
throws UnsupportedEncodingException
{
if (charsetName == null)
throw new NullPointerException("charsetName");
checkBounds(bytes, offset, length);
char[] v = StringCoding.decode(charsetName, bytes, offset, length);
this.offset = 0;
this.count = v.length;
this.value = v;
}
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);
char[] v = StringCoding.decode(bytes, offset, length);
this.offset = 0;
this.count = v.length;
this.value = v;
}
public String(byte bytes[]) {
this(bytes, 0, bytes.length);
}
public String(StringBuffer buffer) {
String result = buffer.toString();
this.value = result.value;
this.count = result.count;
this.offset = result.offset;
}
public String(StringBuilder builder) {
String result = builder.toString();
this.value = result.value;
this.count = result.count;
this.offset = result.offset;
}
// Package private constructor which shares value array for speed.
String(int offset, int count, char value[]) {
this.value = value;
this.offset = offset;
this.count = count;
}
public int length() {
return count;
}
public char charAt(int index) {
if ((index < 0) || (index >= count)) {
throw new StringIndexOutOfBoundsException(index);
}
return value[index + offset];
}
public int codePointAt(int index) {
if ((index < 0) || (index >= count)) {
throw new StringIndexOutOfBoundsException(index);
}
return Character.codePointAtImpl(value, offset + index, offset + count);
}
public int codePointBefore(int index) {
int i = index - 1;
if ((i < 0) || (i >= count)) {
throw new StringIndexOutOfBoundsException(index);
}
return Character.codePointBeforeImpl(value, offset + index, offset);
}
public int codePointCount(int beginIndex, int endIndex) {
if (beginIndex < 0 || endIndex > count || beginIndex > endIndex) {
throw new IndexOutOfBoundsException();
}
return Character.codePointCountImpl(value, offset+beginIndex, endIndex-beginIndex);
}
public int offsetByCodePoints(int index, int codePointOffset) {
if (index < 0 || index > count) {
throw new IndexOutOfBoundsException();
}
return Character.offsetByCodePointsImpl(value, offset, count,
offset+index, codePointOffset);
}
/**
* Copy characters from this string into dst starting at dstBegin.
* This method doesn't perform any range checking.
*/
void getChars(char dst[], int dstBegin) {
System.arraycopy(value, offset, dst, dstBegin, count);
}
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);
}
string在c语言中是什么意思?
String就是C等编程语言中的字符串,用双引号引起来的几个字符。在java、C#中,String类是不可变的,对String类的任何改变,都是返回一个新的String类对象。String对象是 System.Char 对象的有序集合,用于表示字符串。String对象的值是该有序集合的内容,并且该值是不可变的。可以使用以下方法之一来创建...
string类可以被继承吗
string类不可以被继承。string是Java的一种数据类型。在Java中,string类的定义为publicfinalclassStringextendsObject,其中包含final关键字,属于被final修饰的类,所以不能被继承。final类无法被继承,这使得JIT在处理字符串时可以进行各种优化——永远不需要检查被覆盖的方法。Java语言的特点 1、Java语言是...
在java中String...是什么意思
string是编程语言中的字符串,String类是不可变的,对String类的任何改变,都是返回一个新的String类对象。 String 对象是 System.Char 对象的有序集合,用于表示字符串。String 对象的值是该有序集合的内容,并且该值是不可变的。
代码string是什么意思
在Java编程语言中,我们经常会遇到"String"这个词。当这个词大写时,它指的是Java中的一个核心类,全称为"String类"。这个类在程序中扮演着至关重要的角色,它代表了文本数据的集合,用于存储和操作字符序列。无论是字符串常量("Hello, World!")还是通过new关键字创建的对象(new String("example")...
在java中String...是什么意
String类是Java语言中用来表示字符串的对象,其本质是一个有序的char对象集合,其内容一旦创建就固定不变。这意味着对String对象的任何操作,如修改或替换,实际上会返回一个新的String对象,而不是直接改变原始对象。这是因为String是不可变的,确保了数据的完整性。String类提供了丰富的功能,包括比较字符...
C#与Java有什么区别啊?
Java和C#都是编程的语言,它们是两个不同方向的两种语言 相同点:他们都是面向对象的语言,也就是说,它们都能实现面向对象的思想(封装,继承,多态)区别:1.c#中的命名空间是namespace类似于Java中的package(包),在Java中导入包用import而c#中用using。2.c#和Java都是从main函数入口的,但是c#中的...
string是什么数据类型?
string属于Java中的字符串类型,也是一个引用类型,并不属于基本的数据类型。Java中基本的数据类型只有八个,分别是数值型:byte、short、int、long;浮点型:float、double;字符型:char;布尔型:boolean。Java有字符串常量池机制,在声明字符串常量和字符串常量连接都需要使用到字符串常量池,如果字符串...
string在c语言中是什么意思?
在C语言中,string被定义为一个特殊的对象,它代表一个有序的字符序列,这些字符被双引号括起来,共同构成了字符串。不同于其他编程语言,如Java和C#中的String类,C语言中的string本质上是char类型的数组,其值不可变,即一旦创建,其内容就不能被修改,任何操作都会生成新的string对象。创建string对象...
Java语言中的String类跟byte、short、long、int、float、double、char...
String属于引用数据类型,这就是Java提供的字符串类,内部封装了很多方法(函数),简洁又安全 那八种属于基础数据类型;这八种也有对应的引用数据类型 int对应Integer char对应Character 其他都是首字母大写 例如long对应Long 引用类型是将基础数据类型进行封装,提供更丰富的功能 ...
在java中String...是什么意思
(1)String类是final类,也即意味着String类不能被继承,并且它的成员方法都默认为final方法。在Java中,被final修饰的类是不允许被继承的,并且该类中的成员方法都默认为final方法。(2)String对象一旦被创建就是固定不变的了,对String对象的任何改变都不影响到原对象,相关的任何change操作都会生成新...