对数字段进行排序,String,Integer,Arrays,ArrayList,Scanner
2017-12-14 08:50
260 查看
package test; import java.util.ArrayList; import java.util.Arrays; import java.util.Scanner; public class LianXi { public static void main(String[] args) { System.out.println("Enter the number, enter 's' to exit:"); ArrayList<Integer> list = new ArrayList<>(); String s = ""; do { Scanner scanner = new Scanner(System.in); s = scanner.nextLine(); if (s.equals("s")) { break; } else { list.add(Integer.parseInt(s)); } } while (!s.equals("s")); int[] ints = new int[list.size()]; for (int i = 0; i < list.size(); i++) { ints[i] = list.get(i); } Arrays.sort(ints); for (int i : ints) { System.out.println(i + ""); } } } /* String boolean equals(Object anObject) // "" Compares this string to the specified object. Integer static int parseInt(String s) Parses the string argument as a signed decimal integer. static int parseInt(String s, int radix) Parses the string argument as a signed integer in the radix specified by the second argument. Arrays static void sort(byte[] a) Sorts the specified array into ascending numerical order. static void sort(byte[] a, int fromIndex, int toIndex) Sorts the specified range of the array into ascending order. ArrayList<object> boolean add(E e) Appends the specified element to the end of this list. E get(int index) Returns the element at the specified position in this list. remove() set() size() contains() Scanner Scanner(InputStream source) Constructs a new Scanner that produces values scanned from the specified input stream. String nextLine() Advances this scanner past the current line and returns the input that was skipped. */
相关文章推荐
- ArrayList对动态数组进行排序数组由Scanner后台动态接收数组元素
- [转]DISTINCT 和 ORDER BY 使用第三个字段进行排序
- Java 基础小知识二:使用Comparator 对ArrayList 进行排序
- 任意对象数组ArrayList的排序法(可自定义排序字段、排序方向)
- 对ArrayList进行按某种要求进行排序
- mysql将数字组成的字符串字段按照字符串数值型的大小进行排序
- 【java】反射(二)——泛型集合(在ArrayList<Integer>中加入String对象)
- 对List<Map<String,Object>>进行排序
- java list对元素进行指定多个字段属性按多种排序方式进行排序
- 对bean进行某个字符字段排序
- 使用Collections.sort()对List/ArrayList进行排序 推荐
- Java中对ArrayList进行排序
- 利用Arrays.sort(Array,Comparator)对数组进行排序
- oracle数据库中的某个字段根据中文拼音的首字母进行排序
- 根据value字段对map进行排序
- 数组排序-Arrays.sort() 和 复杂类型排序-ArrayList(Student)
- delphi StringGrid单击表头进行高速排序
- List<Entity>排序:根据javabean中的一个字段对beanList进行排序
- C# 对Llist<T>中的数据按某字段的大小进行排序
- mysql数据库按照同一字段不同值进行排序