标签:compare bottom idt lang 初始化 from arc 表示 cannot
int[] a;
int a[];
两种方式。一般选择第一种,比较一目了然。
初始化,必须指定长度:
int[] a = new int[10];
int[] a = {1,2,3};
结果:
[0, 0, 0]
[null, null]
两种方式。
结果:
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
结果:
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
Exception in thread "main" java.lang.ClassCastException: com.zjf.spring.mybatis.model.Person cannot be cast to java.lang.Comparable
at java.util.ComparableTimSort.countRunAndMakeAscending(Unknown Source)
at java.util.ComparableTimSort.sort(Unknown Source)
at java.util.ComparableTimSort.sort(Unknown Source)
at java.util.Arrays.sort(Unknown Source)
at com.zjf.Test.main(Test.java:13)
结果:
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
[id:1,name:xhj, id:2,name:zjf]
注:Arrays.sort使用的是快速排序算法。
Arrays的API:
方法摘要 | ||
static
| asList(T... a) | |
static int | binarySearch(byte[] a, byte key) | |
static int | binarySearch(char[] a, char key) | |
static int | binarySearch(double[] a, double key) | |
static int | binarySearch(float[] a, float key) | |
static int | binarySearch(int[] a, int key) | |
static int | binarySearch(long[] a, long key) | |
static int | binarySearch(Object[] a, Object key) | |
static int | binarySearch(short[] a, short key) | |
static
| binarySearch(T[] a, T key, Comparator<? super T> c) | |
static boolean | deepEquals(Object[] a1, Object[] a2) | |
static int | deepHashCode(Object[] a) | |
static String | deepToString(Object[] a) | |
static boolean | equals(boolean[] a, boolean[] a2) | |
static boolean | equals(byte[] a, byte[] a2) | |
static boolean | equals(char[] a, char[] a2) | |
static boolean | equals(double[] a, double[] a2) | |
static boolean | equals(float[] a, float[] a2) | |
static boolean | equals(int[] a, int[] a2) | |
static boolean | equals(long[] a, long[] a2) | |
static boolean | equals(Object[] a, Object[] a2) | |
static boolean | equals(short[] a, short[] a2) | |
static void | fill(boolean[] a, boolean val) | |
static void | fill(boolean[] a, int fromIndex, int toIndex, boolean val) | |
static void | fill(byte[] a, byte val) | |
static void | fill(byte[] a, int fromIndex, int toIndex, byte val) | |
static void | fill(char[] a, char val) | |
static void | fill(char[] a, int fromIndex, int toIndex, char val) | |
static void | fill(double[] a, double val) | |
static void | fill(double[] a, int fromIndex, int toIndex, double val) | |
static void | fill(float[] a, float val) | |
static void | fill(float[] a, int fromIndex, int toIndex, float val) | |
static void | fill(int[] a, int val) | |
static void | fill(int[] a, int fromIndex, int toIndex, int val) | |
static void | fill(long[] a, int fromIndex, int toIndex, long val) | |
static void | fill(long[] a, long val) | |
static void | fill(Object[] a, int fromIndex, int toIndex, Object val) | |
static void | fill(Object[] a, Object val) | |
static void | fill(short[] a, int fromIndex, int toIndex, short val) | |
static void | fill(short[] a, short val) | |
static int | hashCode(boolean[] a) | |
static int | hashCode(byte[] a) | |
static int | hashCode(char[] a) | |
static int | hashCode(double[] a) | |
static int | hashCode(float[] a) | |
static int | hashCode(int[] a) | |
static int | hashCode(long[] a) | |
static int | ||
static int | hashCode(short[] a) | |
static void | sort(byte[] a) | |
static void | sort(byte[] a, int fromIndex, int toIndex) | |
static void | sort(char[] a) | |
static void | sort(char[] a, int fromIndex, int toIndex) | |
static void | sort(double[] a) | |
static void | sort(double[] a, int fromIndex, int toIndex) | |
static void | sort(float[] a) | |
static void | sort(float[] a, int fromIndex, int toIndex) | |
static void | sort(int[] a) | |
static void | sort(int[] a, int fromIndex, int toIndex) | |
static void | sort(long[] a) | |
static void | sort(long[] a, int fromIndex, int toIndex) | |
static void | ||
static void | sort(Object[] a, int fromIndex, int toIndex) | |
static void | sort(short[] a) | |
static void | sort(short[] a, int fromIndex, int toIndex) | |
static
| sort(T[] a, Comparator<? super T> c) | |
static
| sort(T[] a, int fromIndex, int toIndex, Comparator<? super T> c) | |
static String | toString(boolean[] a) | |
static String | toString(byte[] a) | |
static String | toString(char[] a) | |
static String | toString(double[] a) | |
static String | toString(float[] a) | |
static String | toString(int[] a) | |
static String | toString(long[] a) | |
static String | ||
static String | toString(short[] a) |
标签:compare bottom idt lang 初始化 from arc 表示 cannot
原文地址:http://www.cnblogs.com/xiaolang8762400/p/7041233.html