Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
53 lines (46 loc) · 1.91 KB

File metadata and controls

53 lines (46 loc) · 1.91 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
/**
* Created by riven_chris on 15/7/15.
*/
public class MyArrays {
public static void main(String[] args) {
List<Integer> list = Arrays.asList(1, 2, 3, 4);
System.out.println(Arrays.deepToString(list.toArray()));
Integer[] i1 = {1, 2, 3, 4, 5};
Integer[] i2 = {5, 6, 7, 8, 9};
int[] i3 = {5, 6, 7, 8, 9};
System.arraycopy(i2, 0, i1, 2, 2);
// System.arraycopy(i2, 0, i1, 2, 4); //ArrayIndexOutOfBoundsException
// System.arraycopy(i3, 0, i1, 2, 2); //ArrayStoreException 不支持自动包装与拆包
System.out.println(Arrays.deepToString(i1));
/** 数组的比较 **/
String[] s7 = new String[4];
Arrays.fill(s7, "hi");
String[] s8 = {new String("hi"), new String("hi"), new String("hi"), new String("hi")};
System.out.println(Arrays.equals(s7, s8));//true 数组相等是基于类容的
String[] s1 = new String[]{"a", "b"};
String[] s2 = new String[]{"a", "b"};
String[] s3 = {"a", "b"};
String[] s4 = {"a", "b"};
String[][] s5 = {{"a", "b"}};
String[][] s6 = {{"a", "b"}};
System.out.println(s1.equals(s2));//false
System.out.println(s3.equals(s4));//false
System.out.println(Arrays.equals(s1, s2));//true
System.out.println(Arrays.equals(s3, s4));//true
System.out.println(Arrays.equals(s5, s6));//false
System.out.println(Arrays.deepEquals(s5, s6));//true
/** 数组元素的比较 **/
String[] s9 = {"a", "c", "b", "d"};
Arrays.sort(s9);
Arrays.sort(s9, Collections.reverseOrder());
Arrays.sort(s9, String.CASE_INSENSITIVE_ORDER);
int index = Arrays.binarySearch(s9, "b");
System.out.println(index);
int i = 1;
System.out.println(~i);
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.