alf*_*alf 16
有两种选择,真的:
例如,
int[] ints = {11367, 11358, 11421, 11530, 11491, 11218, 11789};
Arrays.sort(ints);
System.out.println(Arrays.asList(ints));
Run Code Online (Sandbox Code Playgroud)
那当然假设您已经将整数作为数组.如果您需要先解析它们,请查找String.split和Integer.parseInt.
您可以将它们放入列表中,然后使用它们的自然顺序对它们进行排序,如下所示:
final List<Integer> list = Arrays.asList(11367, 11358, 11421, 11530, 11491, 11218, 11789);
Collections.sort( list );
// Use the sorted list
Run Code Online (Sandbox Code Playgroud)
如果数字存储在同一个变量中,那么你必须以某种方式将它们放入a List然后调用sort,如下所示:
final List<Integer> list = new ArrayList<Integer>();
list.add( myVariable );
// Change myVariable to another number...
list.add( myVariable );
// etc...
Collections.sort( list );
// Use the sorted list
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
126354 次 |
| 最近记录: |