• 字符串进行排序


     1 package cn.check.com;
     2 
     3 import java.util.Arrays;
     4 
     5 public class TestDemo {
     6 
     7     public static void main(String[] args) {
     8         // TODO Auto-generated method stub
     9         String s = "25 13 48 11 65";
    10         String[] ss = s.split(" ");// 得到一个字符串数组
    11         int[] arr = new int[ss.length];// 转换成int数组
    12         // 遍历
    13         for (int x = 0; x < arr.length; x++) {
    14             arr[x] = Integer.parseInt(ss[x]);
    15 
    16         }
    17         Arrays.sort(arr);// 排序
    18         StringBuilder sb = new StringBuilder();
    19         for (int x = 0; x < arr.length; x++) {
    20             sb.append(arr[x]).append(" ");// 把值添加到sb中再添加一个空格
    21         }
    22 
    23         String result = sb.toString().trim();// 去掉字符串前后的空格转成字符串
    24         System.out.println("result:" + result);
    25     }
    26 
    27 }
  • 相关阅读:
    生成器和推导式
    闭包
    python
    python初识函数二
    python函数初识
    python文件操作二
    文件操作
    python集合,深浅copy
    Python安装、配置图文详解
    jsDoc 使用及配置!
  • 原文地址:https://www.cnblogs.com/yschung/p/9290344.html
Copyright © 2020-2023  润新知