String[] aArray = new String[5];
String[] bArray = {"a","b","c", "d", "e"};
String[] cArray = new String[]{"a","b","c","d","e"};
int[] intArray = { 1, 2, 3, 4, 5 };
String intArrayString = Arrays.toString(intArray);
System.out.println(intArray);// [I@7150bd4d
System.out.println(intArrayString);// [1, 2, 3, 4, 5]
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]
String[] stringArray = { "a", "b", "c", "d", "e" };
boolean b = Arrays.asList(stringArray).contains("a");
System.out.println(b);// true
int[] intArray = { 1, 2, 3, 4, 5 };
int[] intArray2 = { 6, 7, 8, 9, 10 };// Apache Commons Lang library
int[] combinedIntArray = ArrayUtils.addAll(intArray, intArray2);
method(new String[]{"a", "b", "c", "d", "e"});
// containing the provided list of elements// Apache common lang
String j = StringUtils.join(new String[] { "a", "b", "c" }, ", ");
System.out.println(j);// a, b, c
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);
Set<String> set = new HashSet<String>(Arrays.asList(stringArray));
System.out.println(set);//[d, e, b, c, a]
int[] intArray = { 1, 2, 3, 4, 5 };
ArrayUtils.reverse(intArray);
System.out.println(Arrays.toString(intArray));//[5, 4, 3, 2, 1]
int[] intArray = { 1, 2, 3, 4, 5 };int[] removed = ArrayUtils.removeElement(intArray, 3);//create a new array
System.out.println(Arrays.toString(removed));
byte[] bytes = ByteBuffer.allocate(4).putInt(8).array();for (byte t : bytes) {
System.out.format("0x%x ", t);
}
HashMap用法
实例化:
HashMap<String,String> map= new HashMap<String,String>();
常用方法:
(1)put(K key, V value)
(2)get(Object key)
(3)size()
(4)clear()
(5)isEmpty ()
(6)remove(Object key)
(7)values()
(8)keySet()
//将key作为元素转存入一个set集合。
Set<String> set = map.keySet();
for (String key : set) {
System.out.println(key + " " + map.get(key));
}
(9)entrySet()
//将每一组key-value变为一个entry对象存入set集合
Set<Entry<String, Integer>> set = map.entrySet();
for (Entry<String, Integer> entry : set) {
System.out.println(entry.getKey() + ":" + entry.getValue());}
(10)iterator 迭代器
a、与get()方法结合:
b、与entry对象结合:
栈用法
Stack<Integer> stack = new Stack<>();
常用方法:
push( num) //入栈
pop() //栈顶元素出栈
empty() //判定栈是否为空
peek() //获取栈顶元素
search(num) //判断元素num是否在栈中,如果在返回1,不在返回-1。
队列
//add()和remove()方法在失败的时候会抛出异常(不推荐)
Queue<String> queue = new LinkedList<String>();
offer() //添加元素
Poll() //返回第一个元素,并在队列中删除
element() //返回第一个元素
queue.peek() //返回第一个元素 2. Get the first element - return null if queue is empty.
size()