In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
Editor to share with you how to use the Arrays array tools in Java, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
Method list method name briefly describes asList () returns a list of fixed sizes supported by the specified array. Sort () sort the array (ascending order) parallelSort () sort the specified array in ascending order binarySearch () use the binary search method to quickly find the specified value (provided the array must be ordered) compare () compare two arrays compareUnsigned () compare two arrays in dictionary order Process numeric elements as unsigned copyOf () fill copy array copyOfRange () copy the specified range of the array to a new array equals () compare two arrays deepEquals () compare two array depths toString () convert an array to a string deepToString () convert a multidimensional array to a string fill () populate each element of the array mismatch () find and return the first mismatched index between the two arrays If not found, return-1parallelPrefix () use the provided function to operate on the array elements parallelSetAll () use the provided generator function to set up all elements of the specified array in parallel to calculate each element setAll () use the provided generator function to set all the elements of the specified array to calculate the fast positioning detailed operation of each element
Next, I'll use the code to illustrate one by one.
AsList ()
Function: returns a list of fixed sizes supported by the specified array
Parameter: asList (T … a)
Return value: a list
Code example:
@ Test public void asListTest () {List ss = Arrays.asList ("hello", "world"); / / List ss1 = Arrays.asList ("hello", "world", 1); the type must always (generic) System.out.println (ss); / / [hello, world] / / ss.add ("java"); / / UnsupportedOperationException will report errors / / ss.remove (1) / / UnsupportedOperationException will report System.out.println (ss.get (0)); / / hello ss.set (0, "java"); System.out.println (ss); / / [java, world]}
Be careful
After converting this array to a list, the corresponding list does not support add and delete operations, otherwise an error will be reported.
But you can modify and get elements
ToString () and deepToString ()
Function: convert an array to a string
Parameters: array to be converted
Return value: converted string
Code example:
@ Test public void asListTest () {List ss = Arrays.asList ("hello", "world"); / / List ss1 = Arrays.asList ("hello", "world", 1); the type must always (generic) System.out.println (ss); / / [hello, world] / / ss.add ("java"); / / UnsupportedOperationException will report errors / / ss.remove (1) / / UnsupportedOperationException will report System.out.println (ss.get (0)); / / hello ss.set (0, "java"); System.out.println (ss); / / [java, world]} sort () and parallelSort ()
Function: all sort the array (default ascending order, support lambda, generic)
Parameters:
Sort (Object [] a [, int fromIndex, int toIndex])
Or sort (T [] a [, int fromIndex, int toIndex,] Comparator
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.