Here is a list of the top ten methods of the Java Array. They stackoverflow the biggest vote in the question.
The following is top ten methods for Java Array. They is the most voted questions from StackOverflow.
0. Declaring an array
0. Declare an array
New String[5= {"A", "B", "C", "D", "E"= {"A", "B", "C", "D", "E"};
1. Print an array
1. Print an array in Java
int [] Intarray = {1, 2, 3, 4, 5= arrays.tostring (intarray); // Direct output array, output, memory address: [[email protected]System.out.println (intarray); // output: [1, 2, 3, 4, 5] System.out.println (intarraystring);
2. Convert from array to ArrayList
2. Create an ArrayList from an array
String[] Stringarray = {"A", "B", "C", "D", "E"}; ArrayListNew arraylist<>(arrays.aslist (Stringarray));
Outputs [A, B, C, D, E] System.out.println (arrayList);
3. Determine if the array contains a value
3. Check If an array contains a certain value
String[] Stringarray = {"A", "B", "C", "D", "E"}; Boolean b = arrays.aslist (Stringarray). Contains ("a");
True System.out.println (b);
4. Connect two arrays
4. Concatenate, arrays
// need to import Org.apache.commons.lang3 int [] IntArray1 = {1, 2, 3, 4, 5int[] IntArray2 = {6, 7, 8, 9, tenint[] Combinedintarray ==//[1, 2, 3, 4, 5, 6, 7, 8, 9, ten] System.out.println (arraystring);
5.Declare An array inline---do not know the effect of this
Method (new string[]{"A", "B", "C", "D", "E"});
6. Each element of the array is taken out and stitched into a string
6. Joins the elements of the provided array into a single String
String j = org.apache.commons.lang3.StringUtils.join (new string[] {"A", "B", "C"}, ":");
A:b:c System.out.println (j);
7. Convert ArrayList to arrays
7.Covnert an ArrayList to an array
String[] Stringsarray = {"A", "B", "C", "D", "E"}; ArrayListNew arraylist<>new string[arraylist.size ()]; Arraylist.toarray (Stringarr);
8. Converting an array to a set
8. Convert an array to a set
String[] Stringsarray = {"A", "B", "C", "D", "E"}; set<string> set = new Hashset<string> (arrays.aslist (Stringsarray)); SYSTEM.OUT.PRINTLN (set);
9. Invert an array
9. Reverse an array
String[] Stringsarray = {"A", "B", "C", "D", "E"//[E, D, C, B, a] System.out.println (arrays.tos Tring (Stringsarray));
10. Move an element of an array
Ten. Remove element of an array
Int[] Intarray = {1, 2, 3, 4, 5}; int[] removed = Arrayutils.removeelement (Intarray, 3);//create a new array System.out.println (arrays.tostring (removed) );
One more-convert int to byte array
byte[] bytes = bytebuffer.allocate (4). Putint (8). Array (); for (byte t:bytes) { System.out.format ("0x%x", t);}
Top ten methods of the "Translate" Java Array (Methods for Java Arrays)