-
Notifications
You must be signed in to change notification settings - Fork 53
io microsphere util ArrayUtils
Type: Class | Module: microsphere-java-core | Package: io.microsphere.util | Since: 1.0.0
Source:
microsphere-java-core/src/main/java/io/microsphere/util/ArrayUtils.java
The utilities class for Array
public abstract class ArrayUtils implements UtilsAuthor: Mercy
-
Introduced in:
1.0.0 -
Current Project Version:
0.1.10-SNAPSHOT
This component is tested and compatible with the following Java versions:
| Java Version | Status |
|---|---|
| Java 8 | ✅ Compatible |
| Java 11 | ✅ Compatible |
| Java 17 | ✅ Compatible |
| Java 21 | ✅ Compatible |
| Java 25 | ✅ Compatible |
String[] strings = ArrayUtils.of("one", "two", "three");
Integer[] integers = ArrayUtils.of(1, 2, 3);boolean[] booleans = ArrayUtils.ofBooleans(true, false, true);byte[] bytes = ArrayUtils.ofBytes((byte) 1, (byte) 2, (byte) 3);char[] chars = ArrayUtils.ofChars('a', 'b', 'c');short[] shorts = ArrayUtils.ofShorts((short) 1, (short) 2, (short) 3);int[] ints = ArrayUtils.ofInts(1, 2, 3);long[] longs = ArrayUtils.ofLongs(1L, 2L, 3L);float[] floats = ArrayUtils.ofFloats(1.0f, 2.0f, 3.0f);double[] doubles = ArrayUtils.ofDoubles(1.0, 2.0, 3.0);String[] strings = ArrayUtils.ofArray("one", "two", "three");
Integer[] integers = ArrayUtils.ofArray(1, 2, 3);int length = ArrayUtils.length(new boolean[] { true, false }); // returns 2
int nullArrayLength = ArrayUtils.length((boolean[]) null); // returns 0int length = ArrayUtils.length(new byte[] { 1, 2 }); // returns 2
int nullArrayLength = ArrayUtils.length((byte[]) null); // returns 0int length = ArrayUtils.length(new char[] { 'a', 'b' }); // returns 2
int nullArrayLength = ArrayUtils.length((char[]) null); // returns 0int length = ArrayUtils.length(new short[] { 1, 2 }); // returns 2
int nullArrayLength = ArrayUtils.length((short[]) null); // returns 0int length = ArrayUtils.length(new int[] { 1, 2, 3 }); // returns 3
int nullArrayLength = ArrayUtils.length((int[]) null); // returns 0int length = ArrayUtils.length(new long[] { 1L, 2L }); // returns 2
int nullArrayLength = ArrayUtils.length((long[]) null); // returns 0int length = ArrayUtils.length(new float[] { 1.0f, 2.0f }); // returns 2
int nullArrayLength = ArrayUtils.length((float[]) null); // returns 0int length = ArrayUtils.length(new double[] { 1.0, 2.0 }); // returns 2
int nullArrayLength = ArrayUtils.length((double[]) null); // returns 0Integer[] integers = {1, 2, 3};
int length = ArrayUtils.length(integers); // returns 3
String[] strings = null;
int nullArrayLength = ArrayUtils.length(strings); // returns 0Integer[] integers = {1, 2, 3};
int size = ArrayUtils.size(integers); // returns 3
String[] strings = null;
int nullArraySize = ArrayUtils.size(strings); // returns 0Add the following dependency to your pom.xml:
<dependency>
<groupId>io.github.microsphere-projects</groupId>
<artifactId>microsphere-java-core</artifactId>
<version>${microsphere-java.version}</version>
</dependency>Tip: Use the BOM (
microsphere-java-dependencies) for consistent version management. See the Getting Started guide.
import io.microsphere.util.ArrayUtils;| Method | Description |
|---|---|
of |
An empty immutable boolean array. |
ofBooleans |
Creates a new boolean array from the provided elements. |
ofBytes |
Creates a new byte array from the provided elements. |
ofChars |
Creates a new char array from the provided elements. |
ofShorts |
Creates a new short array from the provided elements. |
ofInts |
Creates a new int array from the provided elements. |
ofLongs |
Creates a new long array from the provided elements. |
ofFloats |
Creates a new float array from the provided elements. |
ofDoubles |
Creates a new double array from the provided elements. |
ofArray |
Creates an array from the provided elements. |
length |
Returns the length of the provided array. |
length |
Returns the length of the provided byte array. |
length |
Returns the length of the provided char array. |
length |
Returns the length of the provided short array. |
length |
Returns the length of the provided int array. |
length |
Returns the length of the provided long array. |
length |
Returns the length of the provided float array. |
length |
Returns the length of the provided double array. |
length |
Returns the length of the provided array. |
size |
Returns the length of the provided array. |
public static boolean[] ofBooleans(boolean... values)Creates a new boolean array from the provided elements.
This method returns an array containing the specified elements. The type of the returned array is explicitly defined by the method's return type.
`boolean[] booleans = ArrayUtils.ofBooleans(true, false, true); `
public static byte[] ofBytes(byte... values)Creates a new byte array from the provided elements.
This method returns an array containing the specified elements. The type of the returned array is explicitly defined by the method's return type.
`byte[] bytes = ArrayUtils.ofBytes((byte) 1, (byte) 2, (byte) 3); `
public static char[] ofChars(char... values)Creates a new char array from the provided elements.
This method returns an array containing the specified elements. The type of the returned array is explicitly defined by the method's return type.
`char[] chars = ArrayUtils.ofChars('a', 'b', 'c');
`
public static short[] ofShorts(short... values)Creates a new short array from the provided elements.
This method returns an array containing the specified elements. The type of the returned array is explicitly defined by the method's return type.
`short[] shorts = ArrayUtils.ofShorts((short) 1, (short) 2, (short) 3); `
public static int[] ofInts(int... values)Creates a new int array from the provided elements.
This method returns an array containing the specified elements. The type of the returned array is explicitly defined by the method's return type.
`int[] ints = ArrayUtils.ofInts(1, 2, 3); `
public static long[] ofLongs(long... values)Creates a new long array from the provided elements.
This method returns an array containing the specified elements. The type of the returned array is explicitly defined by the method's return type.
`long[] longs = ArrayUtils.ofLongs(1L, 2L, 3L); `
public static float[] ofFloats(float... values)Creates a new float array from the provided elements.
This method returns an array containing the specified elements. The type of the returned array is explicitly defined by the method's return type.
`float[] floats = ArrayUtils.ofFloats(1.0f, 2.0f, 3.0f); `
public static double[] ofDoubles(double... values)Creates a new double array from the provided elements.
This method returns an array containing the specified elements. The type of the returned array is explicitly defined by the method's return type.
`double[] doubles = ArrayUtils.ofDoubles(1.0, 2.0, 3.0); `
public static <T> T[] ofArray(T... values)Creates an array from the provided elements.
This method returns an array containing the specified elements. The type of the returned array is inferred from the type of the first element passed, or from the context if the method is used in a typed assignment.
`String[] strings = ArrayUtils.ofArray("one", "two", "three");
Integer[] integers = ArrayUtils.ofArray(1, 2, 3);
`
public static int length(boolean[] values)Returns the length of the provided array.
If the array is null, this method returns 0.
`int length = ArrayUtils.length(new boolean[] { true, false `); // returns 2
int nullArrayLength = ArrayUtils.length((boolean[]) null); // returns 0
}
public static int length(byte[] values)Returns the length of the provided byte array.
If the array is null, this method returns 0.
`int length = ArrayUtils.length(new byte[] { 1, 2 `); // returns 2
int nullArrayLength = ArrayUtils.length((byte[]) null); // returns 0
}
public static int length(char[] values)Returns the length of the provided char array.
If the array is null, this method returns 0.
`int length = ArrayUtils.length(new char[] { 'a', 'b' `); // returns 2
int nullArrayLength = ArrayUtils.length((char[]) null); // returns 0
}
public static int length(short[] values)Returns the length of the provided short array.
If the array is null, this method returns 0.
`int length = ArrayUtils.length(new short[] { 1, 2 `); // returns 2
int nullArrayLength = ArrayUtils.length((short[]) null); // returns 0
}
public static int length(int[] values)Returns the length of the provided int array.
If the array is null, this method returns 0.
`int length = ArrayUtils.length(new int[] { 1, 2, 3 `); // returns 3
int nullArrayLength = ArrayUtils.length((int[]) null); // returns 0
}
public static int length(long[] values)Returns the length of the provided long array.
If the array is null, this method returns 0.
`int length = ArrayUtils.length(new long[] { 1L, 2L `); // returns 2
int nullArrayLength = ArrayUtils.length((long[]) null); // returns 0
}
public static int length(float[] values)Returns the length of the provided float array.
If the array is null, this method returns 0.
`int length = ArrayUtils.length(new float[] { 1.0f, 2.0f `); // returns 2
int nullArrayLength = ArrayUtils.length((float[]) null); // returns 0
}
public static int length(double[] values)Returns the length of the provided double array.
If the array is null, this method returns 0.
`int length = ArrayUtils.length(new double[] { 1.0, 2.0 `); // returns 2
int nullArrayLength = ArrayUtils.length((double[]) null); // returns 0
}
public static <T> int length(T[] values)Returns the length of the provided array.
If the array is null, this method returns 0.
`Integer[] integers = {1, 2, 3`;
int length = ArrayUtils.length(integers); // returns 3
String[] strings = null;
int nullArrayLength = ArrayUtils.length(strings); // returns 0
}
public static <T> int size(T[] values)Returns the length of the provided array.
If the array is null, this method returns 0.
`Integer[] integers = {1, 2, 3`;
int size = ArrayUtils.size(integers); // returns 3
String[] strings = null;
int nullArraySize = ArrayUtils.size(strings); // returns 0
}
This documentation was auto-generated from the source code of microsphere-java.
java-annotations
java-core
- ACLLoggerFactory
- AbstractArtifactResourceResolver
- AbstractConverter
- AbstractDeque
- AbstractEventDispatcher
- AbstractLogger
- AbstractURLClassPathHandle
- AccessibleObjectUtils
- AdditionalMetadataResourceConfigurationPropertyLoader
- AnnotationUtils
- ArchiveFileArtifactResourceResolver
- ArrayEnumeration
- ArrayStack
- ArrayUtils
- Artifact
- ArtifactDetector
- ArtifactResourceResolver
- Assert
- BannedArtifactClassLoadingExecutor
- BaseUtils
- BeanMetadata
- BeanProperty
- BeanUtils
- ByteArrayToObjectConverter
- CharSequenceComparator
- CharSequenceUtils
- CharsetUtils
- ClassDataRepository
- ClassDefinition
- ClassFileJarEntryFilter
- ClassFilter
- ClassLoaderUtils
- ClassPathResourceConfigurationPropertyLoader
- ClassPathUtils
- ClassUtils
- ClassicProcessIdResolver
- ClassicURLClassPathHandle
- CollectionUtils
- Compatible
- CompositeSubProtocolURLConnectionFactory
- CompositeURLStreamHandlerFactory
- ConditionalEventListener
- ConfigurationProperty
- ConfigurationPropertyGenerator
- ConfigurationPropertyLoader
- ConfigurationPropertyReader
- Configurer
- ConsoleURLConnection
- Constants
- ConstructorDefinition
- ConstructorUtils
- Converter
- Converters
- CustomizedThreadFactory
- DefaultConfigurationPropertyGenerator
- DefaultConfigurationPropertyReader
- DefaultDeserializer
- DefaultEntry
- DefaultSerializer
- DelegatingBlockingQueue
- DelegatingDeque
- DelegatingIterator
- DelegatingQueue
- DelegatingScheduledExecutorService
- DelegatingURLConnection
- DelegatingURLStreamHandlerFactory
- DelegatingWrapper
- Deprecation
- Deserializer
- Deserializers
- DirectEventDispatcher
- DirectoryFileFilter
- EmptyDeque
- EmptyIterable
- EmptyIterator
- EnumerationIteratorAdapter
- EnumerationUtils
- Event
- EventDispatcher
- EventListener
- ExceptionUtils
- ExecutableDefinition
- ExecutableUtils
- ExecutorUtils
- ExtendableProtocolURLStreamHandler
- FastByteArrayInputStream
- FastByteArrayOutputStream
- FieldDefinition
- FieldUtils
- FileChangedEvent
- FileChangedListener
- FileConstants
- FileExtensionFilter
- FileUtils
- FileWatchService
- Filter
- FilterOperator
- FilterUtils
- FormatUtils
- Functional
- GenericEvent
- GenericEventListener
- Handler
- Handler
- HierarchicalClassComparator
- IOFileFilter
- IOUtils
- ImmutableEntry
- IterableAdapter
- IterableUtils
- Iterators
- JDKLoggerFactory
- JSON
- JSONArray
- JSONException
- JSONObject
- JSONStringer
- JSONTokener
- JSONUtils
- JarEntryFilter
- JarUtils
- JavaType
- JmxUtils
- ListUtils
- Listenable
- Lists
- Logger
- LoggerFactory
- LoggingFileChangedListener
- MBeanAttribute
- MBeanAttributeInfoBuilder
- MBeanConstructorInfoBuilder
- MBeanDescribableBuilder
- MBeanExecutableInfoBuilder
- MBeanFeatureInfoBuilder
- MBeanInfoBuilder
- MBeanNotificationInfoBuilder
- MBeanOperationInfoBuilder
- MBeanParameterInfoBuilder
- ManagementUtils
- ManifestArtifactResourceResolver
- MapToPropertiesConverter
- MapUtils
- Maps
- MavenArtifact
- MavenArtifactResourceResolver
- MemberDefinition
- MemberUtils
- MetadataResourceConfigurationPropertyLoader
- MethodDefinition
- MethodHandleUtils
- MethodHandlesLookupUtils
- MethodUtils
- ModernProcessIdResolver
- ModernURLClassPathHandle
- Modifier
- MultiValueConverter
- MultipleType
- MutableInteger
- MutableURLStreamHandlerFactory
- NameFileFilter
- NoOpLogger
- NoOpLoggerFactory
- NoOpURLClassPathHandle
- NumberToByteConverter
- NumberToCharacterConverter
- NumberToDoubleConverter
- NumberToFloatConverter
- NumberToIntegerConverter
- NumberToLongConverter
- NumberToShortConverter
- NumberUtils
- ObjectToBooleanConverter
- ObjectToByteArrayConverter
- ObjectToByteConverter
- ObjectToCharacterConverter
- ObjectToDoubleConverter
- ObjectToFloatConverter
- ObjectToIntegerConverter
- ObjectToLongConverter
- ObjectToOptionalConverter
- ObjectToShortConverter
- ObjectToStringConverter
- PackageNameClassFilter
- PackageNameClassNameFilter
- ParallelEventDispatcher
- ParameterizedTypeImpl
- PathConstants
- Predicates
- Prioritized
- PriorityComparator
- ProcessExecutor
- ProcessIdResolver
- ProcessManager
- PropertiesToStringConverter
- PropertiesUtils
- PropertyConstants
- PropertyResourceBundleControl
- PropertyResourceBundleUtils
- ProtocolConstants
- ProxyUtils
- QueueUtils
- ReadOnlyIterator
- ReflectionUtils
- ReflectiveConfigurationPropertyGenerator
- ReflectiveDefinition
- ResourceConstants
- ReversedDeque
- Scanner
- SecurityUtils
- SeparatorConstants
- Serializer
- Serializers
- ServiceLoaderURLStreamHandlerFactory
- ServiceLoaderUtils
- ServiceLoadingURLClassPathHandle
- SetUtils
- Sets
- Sfl4jLoggerFactory
- ShutdownHookCallbacksThread
- ShutdownHookUtils
- SimpleClassScanner
- SimpleFileScanner
- SimpleJarEntryScanner
- SingletonDeque
- SingletonEnumeration
- SingletonIterator
- StackTraceUtils
- StandardFileWatchService
- StandardURLStreamHandlerFactory
- StopWatch
- StreamArtifactResourceResolver
- Streams
- StringBuilderWriter
- StringConverter
- StringDeserializer
- StringSerializer
- StringToArrayConverter
- StringToBlockingDequeConverter
- StringToBlockingQueueConverter
- StringToBooleanConverter
- StringToByteConverter
- StringToCharArrayConverter
- StringToCharacterConverter
- StringToClassConverter
- StringToCollectionConverter
- StringToDequeConverter
- StringToDoubleConverter
- StringToDurationConverter
- StringToFloatConverter
- StringToInputStreamConverter
- StringToIntegerConverter
- StringToIterableConverter
- StringToListConverter
- StringToLongConverter
- StringToMultiValueConverter
- StringToNavigableSetConverter
- StringToQueueConverter
- StringToSetConverter
- StringToShortConverter
- StringToSortedSetConverter
- StringToStringConverter
- StringToTransferQueueConverter
- StringUtils
- SubProtocolURLConnectionFactory
- SymbolConstants
- SystemUtils
- ThrowableAction
- ThrowableBiConsumer
- ThrowableBiFunction
- ThrowableConsumer
- ThrowableFunction
- ThrowableSupplier
- ThrowableUtils
- TrueClassFilter
- TrueFileFilter
- TypeArgument
- TypeFinder
- TypeUtils
- URLClassPathHandle
- URLUtils
- UnmodifiableDeque
- UnmodifiableIterator
- UnmodifiableQueue
- Utils
- ValueHolder
- Version
- VersionUtils
- VirtualMachineProcessIdResolver
- Wrapper
- WrapperProcessor
jdk-tools
lang-model
- AnnotatedElementJSONElementVisitor
- AnnotationUtils
- ClassUtils
- ConstructorUtils
- ElementUtils
- ExecutableElementComparator
- FieldUtils
- JSONAnnotationValueVisitor
- JSONElementVisitor
- LoggerUtils
- MemberUtils
- MessagerUtils
- MethodUtils
- ResolvableAnnotationValueVisitor
- StringAnnotationValue
- TypeUtils
annotation-processor
- ConfigurationPropertyAnnotationProcessor
- ConfigurationPropertyJSONElementVisitor
- FilerProcessor
- ResourceProcessor
java-test
- AbstractAnnotationProcessingTest
- Ancestor
- AnnotationProcessingTestProcessor
- ArrayTypeModel
- CollectionTypeModel
- Color
- CompilerInvocationInterceptor
- ConfigurationPropertyModel
- DefaultTestService
- GenericTestService
- MapTypeModel
- Model
- Parent
- PrimitiveTypeModel
- SimpleTypeModel
- StringArrayList
- TestAnnotation
- TestService
- TestServiceImpl