问答文章1 问答文章501 问答文章1001 问答文章1501 问答文章2001 问答文章2501 问答文章3001 问答文章3501 问答文章4001 问答文章4501 问答文章5001 问答文章5501 问答文章6001 问答文章6501 问答文章7001 问答文章7501 问答文章8001 问答文章8501 问答文章9001 问答文章9501

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);
}
声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com
这是个成本会计题,马上要考这道原题了,求大虾帮忙 财务管理类问题,求大虾帮忙,小弟感激不尽。具体问题看问题补充。_百度... 光影魔术手怎么换底色 光影魔术手换底色教程 ...米的绳子围绕一棵树干饶了6圈,还余下1.16米,这棵树干上的直径大约是... ...还余下1.16米,这棵树的树干的直径大约是多少米?求算式! ibm x3500 M5 服务器 运行时风扇声音好大,吵死了,可以下掉一个吗... IBMX3500 M5,最近老是出现自动关机的情况,需要把服务器电源拔掉半分钟... 治疗萎缩性胃炎的方法 怎么治萎缩胃炎 JYF-40FS06电饭煲190块买的是假的吗 在Java语言中 类是什么 java到底是什么样的语言? java语言的种类 java是一个什么样的编程语言呀? 数据库系统工程师教程电子版 PHP高级工程师所应具备的哪些知识储备 一名合格的PHP工程师的知识结构是怎样的? 新浪微博如何可以暂时注销或者停用?之后想继续开启,粉丝数量是否会变动? 新浪微博如何可以关闭?开了新浪微博,可是想关闭了它,将全部清零,在哪里可以设置?谢谢 有没有办法让新浪微博暂时关闭那种? 系统架构师、系统分析师、软件工程师的关系 到底考系统分析师还是系统架构设计师 c语言是什么语言 不同阶段软件测试工程师薪资对比是什么? 软件测试工程师现在的就业前景如何? 和密码都忘了,怎么才能找回之前的微信? 什么是软件测试工程师呢? 丢了忘记密码了怎样才能找回? 信息系统项目管理师考试难不难? 电子驾照获取方式 “java”语言与其他的语言相比有什么优点? 软件设计需要什么学历 学高级软件设计要什么学历? 考取软件设计师证需不需要考取程序员证 当UI设计师需不需要本科学历? 报考软件设计师 信息系统管理工程师考试考点分析与真题详解的介绍 信息系统管理工程师考试考点分析与真题详解的目录 信息系统管理工程师考试考点分析与真题详解的编辑推荐 中级信息系统管理工程师考试有一本 短平快够不够 软件评测师一年可以考几次?好不好考?考试的时间? 软件测试需要具备哪些条件 软件测试工程师的任职条件有哪些? 一个新手机号怎么注册 如何申请一个新的 我想注册个新,怎么注册? 怎么申请新的? 金华特色美食攻略? 锦绣金华怎么样?好不好?值不值得买? 金华里怎么样?好不好?值不值得买?