https://blog.csdn.net/andyzhaojianhui/article/details/78704219 The following content is from the above URL
Underside of stackoverflow, the number of votes, the number of votes, and the number of votes in the problem. 1. Statement
Java code
String[] aArray = new String[5];
String[] bArray = {"a","b","c", "d", "e"};
String[] cArray = new String[]{"a","b","c","d","e"};
2. Export one piece
Java code
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. Included number of units
Java code
String[] stringArray = { "a", "b", "c", "d", "e" };
ArrayList
System.out.println(arrayList);
// [a, b, c, d, e]
4. 检 查 1 piece number set inclusion / rejection certain piece
Java code
String[] stringArray = { "a", "b", "c", "d", "e" };
boolean b = Arrays.asList(stringArray).contains("a");
System.out.println(b);
// true
5. Jacobs bogie
Java code
int[] intArray = { 1, 2, 3, 4, 5 };
int[] intArray2 = { 6, 7, 8, 9, 10 };
// Apache Commons Lang library
int[] combinedIntArray = ArrayUtils.addAll(intArray, intArray2);
6. Statement within an array (Array inline)
Java code
method(new String[]{"a", "b", "c", "d", "e"});
7. Included number element release single character skewer
Java code
// 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
8. General number group list conversion number group
Java code
String[] stringArray = { "a", "b", "c", "d", "e" };
ArrayList
String[] stringArr = new String[arrayList.size()];
arrayList.toArray(stringArr);
for (String s : stringArr)
System.out.println(s);
9. A collection of conversions (set)
Java code
Set
System.out.println(set);
//[d, e, b, c, a]
10. Reverse single array
Java code
int[] intArray = { 1, 2, 3, 4, 5 };
ArrayUtils.reverse(intArray);
System.out.println(Arrays.toString(intArray));
//[5, 4, 3, 2, 1]
11. Elements in the transfer number
Java code
int[] intArray = { 1, 2, 3, 4, 5 };
int[] removed = ArrayUtils.removeElement(intArray, 3);//create a new array
System.out.println(Arrays.toString(removed));
12. General integer conversion type array number set
Java code
byte[] bytes = ByteBuffer.allocate(4).putInt(8).array();
for (byte t : bytes) {
System.out.format("0x%x ", t);
}
Text origin andyzhaojianhui-like CSDN Expo, full-text site 击: https://blog.csdn.net/andyzhaojianhui/article/details/78704219?utm_source=copy
Recommended Posts