The following is a 12 array operation method that obtains the maximum number of votes in the related question about array methods in StackOverflow.
1. Declare an array
string[] Aarray = new String[5];
String[] Barray = {"A", "B", "C", "D", "E"};
2. Output an array
Int[] Intarray = {1, 2, 3, 4, 5};
String intarraystring = arrays.tostring (intarray);
Print directly'll print reference value
System.out.println (intarray);
[I@7150bd4d
System.out.println (intarraystring);
[1, 2, 3, 4, 5]
3. Create an array list from an array
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. Check whether an array contains a value
String[] Stringarray = {"A", "B", "C", "D", "E"};
Boolean B = Arrays.aslist (Stringarray). Contains ("a");
System.out.println (b);
True
5. Connect two arrays
Int[] Intarray = {1, 2, 3, 4, 5};
Int[] IntArray2 = {6, 7, 8, 9, ten};
Apache Commons Lang Library
6. Declare an inline array (array inline)
Method (New string[]{"A", "B", "C", "D", "E"});
7. Put the provided array elements into a string
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. Convert an array list to arrays
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);
9. Convert an array to a set (set)
set<string> set = new Hashset<string> (arrays.aslist (Stringarray));
SYSTEM.OUT.PRINTLN (set);
[D, E, B, C, a]
10. Reverse an array
Int[] Intarray = {1, 2, 3, 4, 5};
Arrayutils.reverse (intarray);
System.out.println (arrays.tostring (Intarray));
[5, 4, 3, 2, 1]
11. Remove elements from the divisor group
Int[] Intarray = {1, 2, 3, 4, 5};
int[] removed = Arrayutils.removeelement (Intarray, 3);//create a new array
System.out.println (arrays.tostring ( removed));
12. Convert an integer to a byte array
byte[] bytes = bytebuffer.allocate (4). Putint (8). Array ();
for (byte t:bytes) {
System.out.format ("0x%x", t);
}
The above is the Java array Data collation, follow-up continue to supplement the relevant information, thank you for your support of this site!