java 字串陣列 操作

2021-06-16 05:33:41 字數 1014 閱讀 8970

public class stringtool

system.out.println(" size="+a.length+"]");

}/**

* 將字元陣列中下標為idx的字串從陣列src中刪除,idx從0開始

* @param src

* @param idx

* @return 返回刪除指定元素後的陣列

*/public static string removeelement(string src ,int idx)

string result = new string[src.length-1];

for(int i = 0;iidx)

}for(int j = 0;j=length)

string result = new string[length-1];

system.arraycopy(src, 0, result, 0, index);

system.arraycopy(src, index+1, result, index, length-index-1);

return result;

}/**

* 刪除src字串陣列中值與string元素相同的所有元素

* @param src

* @param string

* @return

*/public static string remove(string src ,string string)

}} else }}

return src;

}/**

* 剔除字串陣列中重複字串,

* 在兩個重複的字串中將先剔除第二次出現的字串

* @param src

* @return 返回無重複元素的字串陣列

*/public static string removerepeat(string src)else if(src[i].equals(src[j]))}}

return src;

}

java字串操作

1.宣告字串操作 char a string s new string a 1 string s new string a,2,4 2 string str str good 3 string str2 new string good 4 2 連線字串,使用 運算子可以實現多個字串連線的功能,但是要...

Java 操作字串

1.統計字串的長度,中文佔 2 個字元 獲取字串的長度,如果有中文,則每個中文字元計為2位 param value 指定的字串 return 字串的長度 public static int getstrlength string value else return valuelength 2.擷取指...

java字串操作

string類的方法 1.提取字串的長度,使用length char chars string s new string chars int leng length 2.提取字串指定字元使用charat char chars chars hello charat 1 return e 3.提取字串中...