[JAVA] 12 of Array

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 arrayList = new ArrayList(Arrays.asList(stringArray));
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 arrayList = new ArrayList(Arrays.asList(stringArray));
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 set = new HashSet(Arrays.asList(stringArray));
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

12 of Array
Array
[Java] array
[Ruby] Array
Java array
Array practice
Java array
java (array)
Java array
Array practice 2
Java array
Explanation about Array object of Ruby
java array
[Java] Array
Extract elements of array / extract in reverse order-java
Array # sum of ActiveSupport changes seven times
Convert an array of strings to numbers
[Java beginner] About initialization of multidimensional array
Sort an array of Ruby homebrew classes
java array variable
About array multiplication
Customization of validation
JavaScript array manipulation
Introduction of pay.jp
[Java] Array notes
Basics of Ruby
Array / list / map
Implementation of GKAccessPoint
Array is object
Verification of [email protected]
Elimination of Style/BraceletsAroundHashParameters
Studying Java-Part 7-Array
Ruby array manipulation
[Java] Overview of Java
Release of Hamcrest 2.1
Meaning of final
Behavior of ThreadPoolTaskExecutor
Convert the array of errors.full_messages to characters and output
Mutual conversion of Bitmap / JPEG / byte array on Android
I got stuck in a clone of a two-dimensional array