對字符串中字符進行自然順序排序。“abcwerthelloyuiodef”

1)字符串變成字符數組。


2)對數組排序,選擇,冒泡,Arrays.sort(str.toCharArray());


3)將排序後的數組變成字符串。

	public void testSort() {
		String str = "abcwerthelloyuiodef";
		char[] arr = str.toCharArray();
		Arrays.sort(arr);

		String newStr = new String(arr);
		System.out.println(newStr);
	}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章