StringBuolder可以修改的字符串
创建StringBuilder k=new StringBuilder("可以在里面添加初值");
添加与反转
StringBuilder a=k.append("添加内容");
StringBuilder a=k.reverse();
a和k都是修改之后的结果
StringBuolder与String相互转换
package heima;
import javax.sound.sampled.Line;
import java.util.Scanner;
public class a1 {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
String line= sc.nextLine();
String line1=myReverse(line);
String line2=fzsjb(line);
System.out.println(line+line1+line2);
}
public static String myReverse(String s){
StringBuilder sb=new StringBuilder(s);
sb.reverse();
String ss=sb.toString();
return ss;
}
public static String fzsjb(String s){//反转升级版
return new StringBuilder(s).reverse().toString();
}
}
package heima;
import java.util.Scanner;
public class ss {
public static void main(String[] argc) {
int []arr={1,2,3};
String s=arrayToString(arr);
System.out.println("s"+s);
}
public static String arrayToString(int[] arr){
StringBuilder sb=new StringBuilder();
sb.append("[");
for(int i=0;i
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)