public class test48 { //连接字符串 public static String concatString ( String base , String [] str ){ StringBuilder builder = new StringBuilder ( base ); //构建可变字符串 for ( String s : str ){ builder . append ( " " + s ); } r
//连接字符串
public static String concatString(String base,String[] str){
StringBuilder builder=new StringBuilder(base);//构建可变字符串
for(String s:str){
builder.append(" "+s);
}
return builder.toString();
}
//删除空格
public static String deleteSpace(String target){
while(target.contains(" ")){
StringBuilder builder=new StringBuilder(target);
int index=builder.indexOf(" ");
builder.deleteCharAt(index);
target=builder.toString();
}
return target;
}
}
测试类
public class test49 {
public static void main(String[] args){
StringBuilder builder=new StringBuilder("我是一个热血的少年");
//System.out.println(builder);
String str="今天会下雨吗";
String[] strs={"会的","也许会的","谁知道呢"};
String str1=test48.concatString(str,strs);
System.out.println(str1);
String str3="我 是 歌谣";
//test48.deleteSpace(str3);
String str4=test48.deleteSpace(str3);
System.out.println(str4);
}
}