並べ替えられた、順序なしの文字列型の組み合わせの数

1. 各数値を取り出して配列に保存し、並べ替えてつなぎ合わせます。 

使用: 分割、Arrays.sort、StringBuilder 

public class ceshi {
    public static void main(String[] args) {
        String a = "01,03,02,11,14,22,11";

        String[] split = a.split(",");

        int[] s1 = new int[split.length];
        for (int i = 0; i <split.length ; i++) {
            s1[i] = Integer.parseInt(split[i]);
        }

        Arrays.sort(s1);

        StringBuilder stringBuf = new StringBuilder();
        for (int i = 0; i <s1.length ; i++) {
            stringBuf.append(s1[i]+" ");
        }
        stringBuf.deleteCharAt(stringBuf.length() - 1);

        String result = stringBuf.toString();
        System.out.println(result);
    }
}

出力される結果は次のとおりです: 1 2 3 11 11 14 22

おすすめ

転載: blog.csdn.net/SUMMERENT/article/details/126524353