String
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了String相关的知识,希望对你有一定的参考价值。
鏍囩锛?a href='http://www.mamicode.com/so/1/%e5%ad%90%e4%b8%b2' title='瀛愪覆'>瀛愪覆 format 涓枃 tps builder eal reg ==
hashCode
public int hashCode() { int h = hash; if (h == 0 && value.length > 0) { //hash 榛樿鍊间负0(姝ゆ椂杩樻病鏈夎绠梙ash) && String涓殑瀛楄妭鏁扮粍鏈夊€?浣跨敤 String str="avc"; hash鍒濆鍊间负0锛屼娇鐢╪ew String("avc"),鏋勯€犳椂璁$畻) char val[] = value; for (int i = 0; i < value.length; i++) { h = 31 * h + val[i]; //涓轰粈涔堜娇鐢?1锛?https://www.cnblogs.com/nullllun/p/8350178.html } hash = h; } return h; }
toCharArray
public char[] toCharArray() { // Cannot use Arrays.copyOf because of class initialization order issues char result[] = new char[value.length]; System.arraycopy(value, 0, result, 0, value.length); return result; }
銆€銆€System涓殑鏂规硶 src 鍘熸暟缁? srcPos 浠庡厓鏁版嵁鐨勮捣濮嬩綅缃紑濮? dest 鐩爣鏁扮粍 destPos 鐩爣鏁扮粍鐨勫紑濮嬭捣濮嬩綅缃? length 瑕乧opy鐨勬暟缁勭殑闀垮害 public static native void arraycopy(Object src, int srcPos, Object dest, int destPos, int length);
getChars
public void getChars(int srcBegin, int srcEnd, char dst[], int dstBegin) { if (srcBegin < 0) { throw new StringIndexOutOfBoundsException(srcBegin); } if (srcEnd > value.length) { throw new StringIndexOutOfBoundsException(srcEnd); } if (srcBegin > srcEnd) { throw new StringIndexOutOfBoundsException(srcEnd - srcBegin); } System.arraycopy(value, srcBegin, dst, dstBegin, srcEnd - srcBegin); }
toCharArray 涓?getChars 閮芥槸璋冪敤浜?System.arraycopy
equals
銆€銆€閲嶅啓浜嗘柟娉曪紝鍏堝垽鏂?=锛屽啀鍒ゆ柇鏄惁涓篠tring绫诲瀷锛屽啀鍒ゆ柇闀垮害鐩哥瓑锛屽啀鍒ゆ柇姣忎竴涓厓绱?/pre>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; }2.3 length 瀛楄妭鏁扮粍鐨勫ぇ灏? 2.4 isEmpty 2.5 charAt 2.6 codePointAt 瀵瑰簲绱㈠紩浣嶇疆鐨?ascII鐮佽〃(涓枃)鎴朥nicode浠g爜鐐?鑻辨枃) 2.7 equals 閲嶅啓浜嗘柟娉曪紝鎯冲垽鏂?/span>==锛屽啀鍒ゆ柇鏄惁涓篠tring绫诲瀷锛屽啀鍒ゆ柇闀垮害鐩哥瓑锛屽啀鍒ゆ柇姣忎竴涓厓绱? 2.8 contentEquals 鍙傛暟浼? StringBuffer 鍜?StringBuilder 锛屽绾跨▼涓嶅畨鍏ㄧ殑鍔犻攣锛屾墍浠ヤ笉濂界敤 2.9 equalsIgnoreCase 2.10 compareTo 鐢ㄥ瓧绗︿覆1璺熷瓧绗︿覆2浣滄瘮杈冿紝濡傛灉瀛楃涓?鐨勫瓧鍏搁『搴忓湪瀛楃涓?鍓嶉潰锛屽垯杩斿洖涓€涓礋鏁般€傝嫢鍦ㄥ悗闈紝鍒欒繑鍥炰竴涓鏁般€傝嫢涓や釜瀛楃涓茬殑瀛楀吀椤哄簭鐩稿悓锛屽垯杩斿洖0銆? 鎺掑簭鐨勬椂鍊欎娇鐢? 2.11 compareToIgnoreCase 2.12 regionMatches 浠庡綋鍓嶅瓧绗︿覆鐨刦irstStart浣嶇疆寮€濮嬶紝鍙栦竴涓暱搴︿负len鐨勫瓙涓诧紱鐒跺悗浠庡彟涓€涓瓧绗︿覆other鐨刼therStart浣嶇疆寮€濮嬩篃鍙栦竴涓暱搴︿负len鐨勫瓙涓诧紝鐒跺悗姣旇緝杩欎袱涓瓙涓叉槸鍚︾浉鍚岋紝濡傛灉杩欎袱涓瓙涓茬浉鍚屽垯杩斿洖true锛屽惁鍒欒繑鍥瀎alse 2.13 startsWith(String prefix, int toffset) 娴嬭瘯婧愬瓧绗︿覆鏄惁浠庣储寮晅offset澶勫紑濮嬩互瀛楃涓瞤refix寮€濮? 2.14 indexOf 2.15 lastIndexOf 2.16 substring 2.17 concat 2.18 replace 2.19 matches 璇ユ柟娉曠敤鏉ュ垽鏂繖涓瓧绗︿覆鏄惁鍖归厤缁欏畾鐨勬鍒欒〃杈惧紡 2.20 replaceFirst 2.21 replaceAll 2.22 split 2.23 join 2.24 toLowerCase 2.25 toUpperCase 2.26 trim 2.27 toString 2.28 valueOf 2.29 format 瀛楃涓叉牸寮忓寲 https://segmentfault.com/a/1190000019350486
以上是关于String的主要内容,如果未能解决你的问题,请参考以下文章
Failed to convert property value of type ‘java.lang.String‘ to required type ‘int‘ for property(代码片段
java.lang.NullPointerException: Attempt to invoke virtual method ‘int android.database.sqlite异常(代码片段