merge String(char to String)

时间:2018-06-04 12:22:49

标签: java

我正在练习java编程 这是我的代码,我想合并2个字符串然后排序,

public class MergeString {
    public static void main(String[] args) {
        String str1 = "adfs";
        String str2 = "jiewk";
        String med =mergeString(str1, str2);
        System.out.println(med);
        System.out.println(med.charAt(2));
    }

public static String mergeString(String str1,String str2){
    String merged = str1 +str2;
    char[]merge = merged.toCharArray();
    for (int i =0;i<merge.length;i++){
        for (int j=i+1;j<merge.length-1;j++){
            if (merge[i]>merge[j]){
                char temp = merge[i];
                merge[i]=merge[j];
                merge[j]=temp;

            }
        }
    }
    merged = merge.toString();
    return merged;
}

}

你能告诉我为什么我的输出是ASCII,如:[C @ 6b71769e 非常感谢!

1 个答案:

答案 0 :(得分:3)

使用return String.valueOf(merge)