Arrayutils Tool Class API

Source: Internet
Author: User
Tags addall

Org.apache.commons.lang3.ArrayUtils

//1.add (): Adds the given data to the specified array, returning a new array. int[] arr = {1, 2, 3 };int[] NewArr = Arrayutils.add (arr, 4);//new array length is larger than the old array 1,copy the old array to the new array, assigning the element to the lastSystem.out.println (arrayutils.tostring (NEWARR));//{1,2,3,4}//2.addAll (): Merges two arrays. int[] arr2 = {4, 5, 6 };int[] NewArr =Arrayutils.addall (arr, arr2); System.out.println (arrayutils.tostring (NEWARR)); //{1,2,3,4,5,6}int[] clone = Arrayutils.clone (arr);//call Arr.clone ()System.out.println (arrayutils.tostring (clone));//{ A-i}//3.contains (): Checks if the data exists in the array and returns a Boolean value. Booleancontains = Arrayutils.contains (arr, 2);//traversal judgment equalsSystem.out.println (contains);//true//4.getLength (): Returns the array length. intLength = Arrayutils.getlength (arr);//call Array.getlength (arr)System.out.println (length);//3//5.indexOf (): Queries the array for the specified value from the first bit of the array, and returns the value returned by index, otherwise 1. intIndexOf = Arrayutils.indexof (arr, 2);//traversal judgment equalsSystem.out.println (INDEXOF);//1//6.lastIndexOf (): From the last bit of the array, go ahead and query the array for the specified number, there is a value that returns index, otherwise 1. intLastIndexOf = Arrayutils.lastindexof (arr, 2);//traversal judgment equalsSystem.out.println (INDEXOF);//1//7.Insert (): Adds the specified element to the array to the specified location, returning a new array. int[] NewArr = Arrayutils.insert (2, arr, arr2);//The new array length is the length of the source and destination arrays, and the source and destination arrays are arraycopy to the new arraySystem.out.println (arrayutils.tostring (NEWARR));//{1,2,4,5,6,3}//Extended System.arraycopy () method//Public static void Arraycopy (Object src,int srcpos,object dest,int destpos,int length)//Where: src represents the source array, Srcpos represents the starting position where the source array is to be copied, and DESC represents the target array, and length indicates how long to copy. //Reference:78357325//8.isEmpty (): Determines whether the array is empty and returns a Boolean value. BooleanIsEmpty = Arrayutils.isempty (arr);//call GetLength (array) = = 0;System.out.println (IsEmpty);//falseint[] Arr3 = {1, 2, 3 };BooleanIsequals = Arrayutils.isequals (arr, ARR3);//Deprecated , recommended for use with Arrays.equals (arr, ARR3)System.out.println (isequals);//trueBooleanequals =arrays.equals (arr, ARR3); System.out.println (equals); //true//9.isNotEmpty (): Determines whether the array is empty, not null. BooleanIsnotempty =Arrayutils.isnotempty (arr); System.out.println (Isnotempty); //false//10.isSameLength (): Determines whether the length of the two array is the same, when the array is empty depending on the length of 0. Returns a Boolean value. BooleanIssamelength = Arrayutils.issamelength (arr, ARR3);//call GetLength (arr) = = GetLength (ARR3)System.out.println (issamelength);//true//11.isSameType (): Determines whether the type of two arrays is the same, returns a Boolean value. BooleanIssametype = Arrayutils.issametype (arr, ARR3);//call Array1.getclass (). GetName (). Equals (Array2.getclass (). GetName ())System.out.println (Issametype);//true//12.isSorted (): Determines whether the array is sorted in natural order and returns a Boolean value. Booleanissorted = arrayutils.issorted (arr);//using the comparator implementationSystem.out.println (issorted);//true//13.nullToEmpty ():int[] Nullarr =NULL;int[] Nulltoempty = Arrayutils.nulltoempty (Nullarr);//If arr is null, return new INT[0]System.out.println (arrayutils.tostring (nulltoempty));// {}//14.remove (): Deletes the element at the specified position in the array, returning a new array. int[] NewArr = Arrayutils.remove (arr, 0); System.out.println (arrayutils.tostring (NEWARR)); //{2,3}//15.removeAll (): Deletes the element at the specified position, returning a new array. int[] NewArr = Arrayutils.removeall (arr, 0, 1); System.out.println (arrayutils.tostring (NEWARR)); //{3}//16.removeAllOccurences (): Removes the specified element from the array, returning a new array. int[] NewArr = Arrayutils.removealloccurences (arr, 2);//traversal uses indexof () to find all the specified elements in the execution RemoveAll ()System.out.println (arrayutils.tostring (NEWARR));//{1,3}//17.removeElement (): Removes the first occurrence of the specified element from the array, returning a new array. int[] NewArr = Arrayutils.removeelement (arr, 2);//use indexof () to find the first occurrence of the specified element in the Execute remove ()System.out.println (arrayutils.tostring (NEWARR));//{1,3}//18.removeElements (): Removes the specified number of elements from the array, returning a new array. int[] NewArr = Arrayutils.removeelements (arr, 1, 2); System.out.println (arrayutils.tostring (NEWARR)); //{3}//19.reverse (): array inversion. You can also specify the reversal position of the start and end. Arrayutils.reverse (arr);//Symmetrical ExchangeSystem.out.println (arrayutils.tostring (arr));//{3,2,1}//ShiftArrayutils.shift (arr, 2); System.out.println (arrayutils.tostring (arr)); //{3,2,1}//upsetarrayutils.shuffle (arr); System.out.println (arrayutils.tostring (arr));//20.subarray (): Intercept Array (header not wrapped), return a new arrayint[] Subarray = Arrayutils.subarray (arr, 0, 2); System.out.println (arrayutils.tostring (Subarray)); //{A}//21.swap (): Specifies the two-position element exchange of the array or the length element of Len after specifying two positions. Arrayutils.swap (arr, 0, 1); System.out.println (arrayutils.tostring (arr)); //{2,1,3}//22.toMap (): Converts an array to a map, returning a collection of the object of a map. String[][] Strarr = {{"RED", "#FF0000"}, {"GREEN", "#00FF00"}, {"BLUE", "#0000FF" } }; Map ColorMap=Arrayutils.tomap (Strarr); System.out.println (COLORMAP);//23.toObject (): Converts an array of raw data types into a wrapper class array. Arrayutils.toobject (arr);//Traversal TransformationSystem.out.println (arrayutils.tostring (arr));//integer Type//24.toPrimitive (): Converts the wrapper class array into an array of raw data types. arrayutils.toprimitive (arr); System.out.println (arrayutils.tostring (arr)); //int type//25.toString (): Outputs the array as STIRNG, returning a string. String str =arrayutils.tostring (arr); SYSTEM.OUT.PRINTLN (arrayutils.tostring (str));//26.toStringArray (): Converts an object array to a string array type. string[] StrArr2 =Arrayutils.tostringarray (New object[]{"1", "2"}); System.out.println (arrayutils.tostring (STRARR2)); {A}

Official Document: Https://commons.apache.org/proper/commons-lang/javadocs/api-release/index.html

View Documents: 77987348

Arrayutils Tool Class API

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.