Apache Commons Lang3 Package Arrayutils tool use

Source: Internet
Author: User

Arrayutils has the following methods: ToString converts an array to a string, prints an array isequals determines whether two arrays are equal, uses Equalsbuilder to determine Tomap converts an array into a map, If the array is entry then its key and value are the key and value of the new map, and if it is object[] object[0] for Keyobject[1] for valueclone copy array Subarray intercept sub-array issamelength determine whether two array lengths are equal getlength get the length of the array issametype the type of the two array is the same reverse array inversion indexof query for one of the obj The position of the ECT in the array, you can specify the starting search location LastIndexOf The position of an object in the array, You can specify a starting search location contains query whether an object is in an array toobject convert the base data type to outsourced data IsEmpty determine if the array is empty (null and length=0 is empty) AddAll merge two arrays add a data to an array remove data from a location in the array removeelement delete an object in the array (start the search in the positive order, delete the first) eg://1. Print an arrayArrayutils.tostring (New int[] {1, 4, 2, 3});//{1,4,2,3}Arrayutils.tostring (NewInteger[] {1, 4, 2, 3});//{1,4,2,3}Arrayutils.tostring (NULL, "I ' m nothing!");//I ' m nothing! //2. Determine whether two arrays are equal and use Equalsbuilder to determine//The method returns true only if the data type, length, and numeric order of the two arrays are the same.//2.1 Two arrays are exactly the sameArrayutils.isequals (New int[] {1, 2, 3},New int[] {1, 2, 3});//true//2.2 data type and the same length, but the data on each index is not one by one correspondingArrayutils.isequals (New int[] {1, 3, 2},New int[] {1, 2, 3});//false//2.3 Inconsistent length of arrayArrayutils.isequals (New int[] {1, 2, 3, 3},New int[] {1, 2, 3});//false//2.4 Different data typesArrayutils.isequals (New int[] {1, 2, 3},New Long[] {1, 2, 3});//falseArrayutils.isequals (NewObject[] {1, 2, 3},NewObject[] {1, (Long) 2, 3});//false//2.5 NULL Processing if the input two array is null when the return TrueArrayutils.isequals (New int[] {1, 2, 3},NULL);//falseArrayutils.isequals (NULL,NULL);//true//3. Convert an array to a map//if the array is entry then its key and value are the new map's key and value, if it is object[] [object[0] is keyobject[1] is value//the elements in the object[] array must be instanceof object[] or entry, that is, an array of basic data types is not supported//such as: Arrayutils.tomap (new Object[]{new Int[]{1,2},new int[]{3,4}}) will have an exceptionArrayutils.tomap (NewObject[] {NewObject[] {1, 2},NewObject[] {3, 4}});//{1=2,//3=4}Arrayutils.tomap (NewInteger[][] {NewInteger[] {1, 2},NewInteger[] {3, 4}});//{1=2,//3=4}//4. Copying an arrayArrayutils.clone (New int[] {3, 2, 4});//{3,2,4}//5. Intercepting ArraysArrayutils.subarray (New int[] {3, 4, 1, 5, 6}, 2, 4);//{1,5}//The starting index is 2 (that is, the third data) ends with an array of index 4Arrayutils.subarray (New int[] {3, 4, 1, 5, 6}, 2, 10);//{1,5,6}//if Endindex is greater than the length of the array, all data after Beginindex is taken//6. Determine whether the length of the two arrays is equalArrayutils.issamelength (NewInteger[] {1, 3, 5},NewLong[] {2L, 8L, 10L});//true//7. Get the length of the arrayArrayutils.getlength (New Long[] {1, 23, 3});//3//8. The type of the two array of the sentence is the sameArrayutils.issametype (New Long[] {1, 3},New Long[] {8, 5, 6});//trueArrayutils.issametype (New int[] {1, 3},New Long[] {8, 5, 6});//false//9. Array inversion        int[] Array =New int[] {1, 2, 5 }; Arrayutils.reverse (array);//{5,2,1}//10. Query the position of an object in the array, you can specify the starting search location, cannot find the return-1//10.1 Start searching from the positive sequence, search to return the current index otherwise return-1Arrayutils.indexof (New int[] {1, 3, 6}, 6);//2Arrayutils.indexof (New int[] {1, 3, 6}, 2);//-1//10.2 Search from the reverse order, and search to return the current index otherwise return-1Arrayutils.lastindexof (New int[] {1, 3, 6}, 6);//2//11. Query whether an object is in an arrayArrayutils.contains (New int[] {3, 1, 2}, 1);//true//for object data is called by the Object.Equals method to judgeArrayutils.contains (NewObject[] {3, 1, 2}, 1L);//false//12. An array of basic data types and an array of outsourced data typesArrayutils.toobject (New int[] {1, 2});//New Integer[]{integer,integer}Arrayutils.toprimitive (NewInteger[] {NewInteger (1),NewInteger (2)});//New int[]{1,2}//13. Determine if the array is empty (null and length=0 are empty)Arrayutils.isempty (New int[0]);//trueArrayutils.isempty (NewObject[] {NULL});//false//14. Merging of two arraysArrayutils.addall (New int[] {1, 3, 5},New int[] {2, 4});//{1,3,5,2,4}//15. Adding a data to an arrayArrayutils.add (New int[] {1, 3, 5}, 4);//{1,3,5,4}//16. Delete Data at a location in the arrayArrayutils.remove (New int[] {1, 3, 5}, 1);//{1,5}//17. Delete an object in the array (start the search from the positive order, delete the first one)Arrayutils.removeelement (New int[] {1, 3, 5}, 3);//{1,5}

Apache Commons Lang3 Package Arrayutils tool use

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.