# 1 声明一个array

```String[] aArray = new String[5];
String[] bArray = {"a","b","c", "d", "e"};
String[] cArray = new String[]{"a","b","c","d","e"};```

# 2 打印一个array

```int[] intArray = { 1, 2, 3, 4, 5 };
String intArrayString = Arrays.toString(intArray);
// print directly will print reference value
System.out.println(intArray);
// [I@7150bd4d
System.out.println(intArrayString);
// [1, 2, 3, 4, 5]```

# 3 从array创建一个list

```String[] stringArray = { "a", "b", "c", "d", "e" };
ArrayList<String> arrayList = new
ArrayList<String>(Arrays.asList(stringArray));
System.out.println(arrayList);
// [a, b, c, d, e]```

# 4 检查array中是否存在某个元素

```String[] stringArray = { "a", "b", "c", "d", "e" };
boolean b = Arrays.asList(stringArray).contains("a");
System.out.println(b);
// true```

# 5 连接两个array

```int[] intArray = { 1, 2, 3, 4, 5 };
int[] intArray2 = { 6, 7, 8, 9, 10 };
// Apache Commons Lang library

# 6 Declare an array inline

`method(new String[]{"a", "b", "c", "d", "e"});`

# 7 将一个list转为array

```String[] stringArray = { "a", "b", "c", "d", "e" };
ArrayList<String> arrayList = new
ArrayList<String>(Arrays.asList(stringArray));
String[] stringArr = new String[arrayList.size()];
arrayList.toArray(stringArr);
for (String s : stringArr)
System.out.println(s);```

# 8 array转为set

```Set<String> set = new HashSet<String>(Arrays.asList(stringArray));
System.out.println(set);
//[d, e, b, c, a]```

381 篇文章35 人订阅

0 条评论

## 相关文章

### 数据结构与算法 -- 二叉树链式详解（（非）/递归遍历，叶子个数，深度计算）

PS：树型结构是一种重要的非线性数据结构，教科书上一般都是树与二叉树，由此可见，树和二叉树是有区别和联系的，网上有人说二叉树是树的一种特殊形式，但经过查资料，树...

11450

14110

### LeetCode 144. Binary Tree Preorder Traversal题目分析代码

Given a binary tree, return the preorder traversal of its nodes' values. For ex...

10220

25940

23140

33340

25050

29570

9750

### HOJ 2148&POJ 2680（DP递推，加大数运算）

Computer Transformation Time Limit: 1000MS Memory Limit: 65536K Total S...

302120