<span style="font-size:24px;"><pre name="code" class="java">//需求:对字符串中的字母进行排序,变成有序的字符串。
// "bdacxrtq" --> "abcdqrtx";
//思路:
//1、先把字符串变成数组
//2、对数组元素进行排序
//3、将数组变成字符串
</span>
<span style="font-size:24px;">import java.util.Arrays;
public class StringSort{
public static void main(String[] args) {
System.out.println("对字符串中的字母进行排序,变成有序的字符串。\"bdacxrtq\" --> \"abcdqrtx\"; ");
StringSortMethodOne(); //调用方法一
System.out.println("******************");
StringSortMethodTwo();//调用方法二
}
public static void StringSortMethodOne(){ //方法一:基本思想是用冒泡排序,对字符串数组进行排序
String a ="bdacxrtq"; //字符串a-z可以随意设置
char []arr =a.toCharArray(); //用String中的方法toCharArray,字符串->字符串数组
for (int i = 0; i < arr.length; i++) { //用for嵌套来交换值
f