Top ten methods of the "Translate" Java Array (Methods for Java Arrays)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.