如何将char数组存储回循环中的sting?

时间:2018-04-14 08:56:32

标签: java arrays arraylist char

    Scanner sc = new Scanner(System.in);
    System.out.print("Enter the number to reverse ");

    String mystring = sc.nextLine();    

    char[] my_3 = mystring.toCharArray();   // string converted into array

如何将char数组转换回字符串

    for (int i = my_3.length - 1; i >= 0; i--) {
        System.out.print(my_3[i]);
        String b = new String(my_3[i]);  
                   }

1 个答案:

答案 0 :(得分:1)

试试这个。

String mystring = "abcde";
String reverse = new StringBuilder(mystring).reverse().toString();
System.out.println(reverse); // -> edcba