public class StringTool {
/**
* 在控制台打印字符串数组 a
* @param a
*/
public static void printArray(String[] a){
System.out.print("[");
for(String s : a){
System.out.print(s+",");
}
System.out.println(" size="+a.length+"]");
}
/**
* 将字符数组中下标为idx的字符串从数组src中删除,idx从0开始
* @param src
* @param idx
* @return 返回删除指定元素后的数组
*/
public static String[] removeElement(String[] src ,int idx){
int length = src.length;
if(idx>=length){
throw new IndexOutOfBoundsException();
}
String[] result = new String[src.length-1];
for(int i = 0;iidx){
src[i-1] = src[i];
}
}
for(int j = 0;j字符串从数组src中删除,idx从0开始
* @param src
* @param index
* @return 返回删除指定元素后的数组
*/
public static String[] remove(String[] src ,int index){
int length = src.length;
if(index>=length){
throw new IndexOutOfBoundsException();
}
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){
if(string==null){
for(int i = 0; i字符串数组中重复字符串,
* 在两个重复的字符串中将先剔除第二次出现的字符串
* @param src
* @return 返回无重复元素的字符串数组
*/
public static String[] removeRepeat(String[] src){
for(int i = 0; i<src.length;i++){
for(int j = i+1 ;j<src.length;j++){
if(src[i]==null && src[i]==src[j]){
src = remove(src,j);
j--;
}else if(src[i].equals(src[j])){
src = remove(src,j);
j--;
}
}
}
return src;
}
}
/**
* 在控制台打印字符串数组 a
* @param a
*/
public static void printArray(String[] a){
System.out.print("[");
for(String s : a){
System.out.print(s+",");
}
System.out.println(" size="+a.length+"]");
}
/**
* 将字符数组中下标为idx的字符串从数组src中删除,idx从0开始
* @param src
* @param idx
* @return 返回删除指定元素后的数组
*/
public static String[] removeElement(String[] src ,int idx){
int length = src.length;
if(idx>=length){
throw new IndexOutOfBoundsException();
}
String[] result = new String[src.length-1];
for(int i = 0;iidx){
src[i-1] = src[i];
}
}
for(int j = 0;j字符串从数组src中删除,idx从0开始
* @param src
* @param index
* @return 返回删除指定元素后的数组
*/
public static String[] remove(String[] src ,int index){
int length = src.length;
if(index>=length){
throw new IndexOutOfBoundsException();
}
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){
if(string==null){
for(int i = 0; i字符串数组中重复字符串,
* 在两个重复的字符串中将先剔除第二次出现的字符串
* @param src
* @return 返回无重复元素的字符串数组
*/
public static String[] removeRepeat(String[] src){
for(int i = 0; i<src.length;i++){
for(int j = i+1 ;j<src.length;j++){
if(src[i]==null && src[i]==src[j]){
src = remove(src,j);
j--;
}else if(src[i].equals(src[j])){
src = remove(src,j);
j--;
}
}
}
return src;
}
}