标签:android style java os io for art ar
这是今天阿里电话面试被问到的,在之前确实没有想过(一直以为是一样的),于是面试完之后,我马上打开了源码,对这两个String类进行了比较,下面是我的发现。这是android版本:
import java.io.Serializable; import java.io.UnsupportedEncodingException; import java.nio.ByteBuffer; import java.nio.CharBuffer; import java.nio.charset.Charset; import java.nio.charset.Charsets; import java.util.Arrays; import java.util.Comparator; import java.util.Formatter; import java.util.Locale; import java.util.regex.Pattern; import libcore.util.EmptyArray;//这个貌似是google自己的api类库
import java.io.ObjectStreamField; import java.io.UnsupportedEncodingException; import java.nio.charset.Charset; import java.util.ArrayList; import java.util.Arrays; 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 int compareToIgnoreCase(String string) { int o1 = offset, o2 = string.offset, result; int end = offset + (count < string.count ? count : string.count); char c1, c2; char[] target = string.value; while (o1 < end) { if ((c1 = value[o1++]) == (c2 = target[o2++])) { continue; } c1 = foldCase(c1); c2 = foldCase(c2); if ((result = c1 - c2) != 0) { return result; } } return count - string.count; }
public int compareToIgnoreCase(String str) { return CASE_INSENSITIVE_ORDER.compare(this, str); }
public native char charAt(int index); public native int compareTo(String string); public native boolean equals(Object object); private native int fastIndexOf(int c, int start); public native boolean isEmpty(); public native int length();
public char charAt(int index) { if ((index < 0) || (index >= value.length)) { throw new StringIndexOutOfBoundsException(index); } return value[index]; } public int compareTo(String anotherString) { int len1 = value.length; int len2 = anotherString.value.length; int lim = Math.min(len1, len2); char v1[] = value; char v2[] = anotherString.value; int k = 0; while (k < lim) { char c1 = v1[k]; char c2 = v2[k]; if (c1 != c2) { return c1 - c2; } k++; } return len1 - len2; } public boolean equals(Object anObject) { if (this == anObject) { return true; } if (anObject instanceof String) { String anotherString = (String) anObject; int n = value.length; if (n == anotherString.value.length) { char v1[] = value; char v2[] = anotherString.value; int i = 0; while (n-- != 0) { if (v1[i] != v2[i]) return false; i++; } return true; } } return false; }
java的String和android的String有什么区别?,布布扣,bubuko.com
java的String和android的String有什么区别?
标签:android style java os io for art ar
原文地址:http://blog.csdn.net/chdjj/article/details/38408699