① 在java中怎麼把32位字元串轉成16位唯一的字元串
uuid工具類可以生成32位隨機數,你把他的長度減16就行了。
② java String截取字元串唯一數字
正則表達式
publicstaticvoidmain(String[]args){
Stringstr="sdsdfdsafdsaeafeadsfxca14562";
System.out.println(str.replaceAll("\D",""));
}
③ Java中System.nanoTime方法能作為一個唯一字元串來使用嗎
一般使用 UUID 類來生成唯一的字元串
packagetest;
importjava.util.UUID;
publicclassUUIDGenerator{
publicUUIDGenerator(){
}
publicstaticStringgetUUID(){
UUIDuuid=UUID.randomUUID();
Stringstr=uuid.toString();
//去掉"-"符號
Stringtemp=str.substring(0,8)+str.substring(9,13)+str.substring(14,18)+str.substring(19,23)+str.substring(24);
returnstr+","+temp;
}
//獲得指定數量的UUID
publicstaticString[]getUUID(intnumber){
if(number<1){
returnnull;
}
String[]ss=newString[number];
for(inti=0;i<number;i++){
ss[i]=getUUID();
}
returnss;
}
publicstaticvoidmain(String[]args){
String[]ss=getUUID(10);
for(inti=0;i<ss.length;i++){
System.out.println("ss["+i+"]====="+ss[i]);
}
}
}
④ Java 字元串類型 轉換 Int類型。字元串是唯一的.
public int hashCode()返回該對象的哈希碼值
一致性
在 Java 應用程序執行期間,在對同一對象多次調用 hashCode 方法時,必須一致地返回相同的整數,前提是將對象進行 equals 比較時所用的信息沒有被修改。
也就是說對象的value沒改變時 調用該方法返回的值都是一樣的
在我理解中你的問題是想知道 相同的String調用 hashCode()返回的哈希碼值是不是會有多個
這個哈希碼值是用來標識這個String的
也就出現了域的問題
在從某一應用程序的一次執行到同一應用程序的另一次執行,該整數無需保持一致
所以在某些情況下這個String的哈希碼值並不唯
要說明的一點是上面「一致性」說的equals 是object類中的 該方法是比較的 對象內存地址
⑤ 【JAVA】在網頁代碼中截取一個字元串indexOf方法
你的c1是什麼東東??這樣試試
int c = hideArea.getText().indexOf("Download<");
int d = hideArea.getText().indexOf(">is ooo<i>");
String temp=hideArea.getText().substring(c,d);
還有,你得保證hideArea的"Download<" 和 ">is ooo<i>" 里沒有"Download<" 或 ">is ooo<i>"
⑥ java如何對一個字元串生成唯一的編碼
JAVA類庫中可以使用UUID方法,來生成唯一的數字的一串數字編號,也就是訂單號。
UUID.randomUUID().toString().replaceAll("-", "");通過上述方法就可以返回一串數字字元串。
⑦ java uuid 為什麼是字元串不是整型
uuid是很長的一串根據當前時間區域來劃分的唯一字元串. . .長度有可能超過整數的表示的最大值范圍. .
⑧ java:String.hashcode可以保證多長的字元串的值唯一
java 1.7源碼中,java.lang.String.hashCode()注釋如下:
Returnsahashcodeforthisstring.
s[0]*31^(n-1)+s[1]*31^(n-2)+...+s[n-1]
usingintarithmetic,wheres[i]istheithcharacterofthestring,nisthelengthofthe
string,and^indicatesexponentiation.(Thehashvalueofthe
emptystringiszero.)
具體使用可以參考淺談Java中的hashcode方法