Guava (GOOGLE Common Libraares) original type related function introduction and example code

Guava (Google Common Libraries) is an open source Java library that provides many practical functions, including the original type -related features.This article will introduce the use and example code of the original type related functions in the Guava library. 1. Primary type of packaging class (Primitive Wrapper) GUAVA provides a set of original types of packaging categories to handle conversion between original types and objects.These packaging classes include: -` Booleans`: It is used to handle the operation of Boer type, such as the conversion and operation of the Boer array. -` CHARS`: It is used to handle the operation of the character type, such as the conversion and operation of the character array. -` Doubles`: It is used to handle the operation of dual -precision floating -point types, such as the conversion and operation of dual -precision floating -point array. -` Floats`: It is used to handle the operation of single precision floating -point type, such as the conversion and operation of single -precision floating -point array. -` ints`: used to handle the operation of integer type, such as the conversion and operation of integer array. -` LONGS`: It is used to handle the operation of the integer type, such as the conversion and operation of the long integral array. -` SHORTS`: It is used to handle the operation of short integral types, such as the conversion and operation of the short array. The following is a sample code that demonstrates the function of using the original type packaging class of Guava: the type conversion function: import com.google.common.primitives.Ints; public class PrimitiveWrapperExample { public static void main(String[] args) { int[] intArray = {1, 2, 3, 4, 5}; Integer[] integerArray = Ints.toObjectArray(intArray); for (Integer i : integerArray) { System.out.println(i); } int[] convertedArray = Ints.toArray(integerArray); for (int i : convertedArray) { System.out.println(i); } } } In the above code, the `ints.toobjectArray () method converts the integer array to an integer object array, and the` ints.toarray () method converts the array of integer objects back to the array. 2. Primitive array operations (Primitive Arrays) Guava provides a set of practical methods for processing the original type array, including: -`Booleans`: operations for Boer type arrays, such as finding, sorting, etc. -` Bytes`: The operation of byte type array, such as finding, sorting, etc. -` CHARS`: The operation of the character type array, such as finding, sorting, etc. -` Doubles`: The operations used for dual -precision floating -point type arrays, such as finding, sorting, etc. -` Floats`: The operations for single -precision floating -point type arrays, such as finding, sorting. -` ints`: operations for integer type array, such as finding, sorting, etc. -` LONGS`: The operations of the array of the integral type, such as finding, sorting, etc. -` Shorts`: The operations used for short integers, such as finding, sorting, etc. The following is an example code that shows the operating function of the original type array of the use of Guava: import com.google.common.primitives.Ints; public class PrimitiveArrayExample { public static void main(String[] args) { int[] intArray = {5, 4, 1, 3, 2}; int indexOfOne = Ints.indexOf(intArray, 1); System.out.println("Index of 1: " + indexOfOne); int[] sortedArray = Ints.concat(Ints.asList(intArray), new int[]{6, 7}); System.out.print("Sorted Array: "); for (int i : sortedArray) { System.out.print(i + " "); } } } The method of `ints.indexof ()` in the above code is used to find the indexes of specified elements in the array, and the method of `ints.concat ()` is used to merge the two integer arrays and returns new array sorted. Through the above example code, you can understand the use of the original type related functions in the Guava library.These functions provide a convenient method, which can simplify the conversion between the original type and the object and the operation of the original type array.