类 ListUtils
- java.lang.Object
-
- com.alibaba.excel.util.ListUtils
public class ListUtils extends Object
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.- 作者:
- Apache Software Foundation (ASF)
-
方法概要
所有方法 静态方法 具体方法 限定符和类型 方法和说明 static <T> T
checkNotNull(T reference)
Ensures that an object reference passed as a parameter to the calling method is not null.static <E> ArrayList<E>
newArrayList()
Creates a mutable, emptyArrayList
instance (for Java 6 and earlier).static <E> ArrayList<E>
newArrayList(E... elements)
Creates a mutableArrayList
instance containing the given elements.static <E> ArrayList<E>
newArrayList(Iterable<? extends E> elements)
Creates a mutableArrayList
instance containing the given elements; Note for Java 7 and later: ifelements
is aCollection
, you don't need this method.static <E> ArrayList<E>
newArrayList(Iterator<? extends E> elements)
Creates a mutableArrayList
instance containing the given elements; a very thin shortcut for creating an empty list and then callingIterators.addAll(java.util.Collection<T>, java.util.Iterator<? extends T>)
.static <E> ArrayList<E>
newArrayListWithCapacity(int initialArraySize)
Creates anArrayList
instance backed by an array with the specified initial size; simply delegates toArrayList.ArrayList(int)
.static <E> ArrayList<E>
newArrayListWithExpectedSize(int estimatedSize)
Creates anArrayList
instance to holdestimatedSize
elements, plus an unspecified amount of padding; you almost certainly mean to callnewArrayListWithCapacity(int)
(see that method for further advice on usage).
-
方法详细资料
newArrayList
public static <E> ArrayList<E> newArrayList()
Creates a mutable, emptyArrayList
instance (for Java 6 and earlier).Note for Java 7 and later: this method is now unnecessary and should be treated as deprecated. Instead, use the
ArrayList
constructor directly, taking advantage of the new "diamond" syntax.
newArrayList
public static <E> ArrayList<E> newArrayList(E... elements)
Creates a mutableArrayList
instance containing the given elements.
newArrayList
public static <E> ArrayList<E> newArrayList(Iterator<? extends E> elements)
Creates a mutableArrayList
instance containing the given elements; a very thin shortcut for creating an empty list and then callingIterators.addAll(java.util.Collection<T>, java.util.Iterator<? extends T>)
.
newArrayList
public static <E> ArrayList<E> newArrayList(Iterable<? extends E> elements)
Creates a mutableArrayList
instance containing the given elements;Note for Java 7 and later: if
elements
is aCollection
, you don't need this method. Use theArrayList
constructor directly, taking advantage of the new "diamond" syntax.
newArrayListWithCapacity
public static <E> ArrayList<E> newArrayListWithCapacity(int initialArraySize)
Creates anArrayList
instance backed by an array with the specified initial size; simply delegates toArrayList.ArrayList(int)
.Note for Java 7 and later: this method is now unnecessary and should be treated as deprecated. Instead, use
new
ArrayList
<>(int)
directly, taking advantage of the new "diamond" syntax. (Unlike here, there is no risk of overload ambiguity, since theArrayList
constructors very wisely did not accept varargs.)- 参数:
-
initialArraySize
- the exact size of the initial backing array for the returned array list (ArrayList
documentation calls this value the "capacity") - 返回:
-
a new, empty
ArrayList
which is guaranteed not to resize itself unless its size reachesinitialArraySize + 1
- 抛出:
-
IllegalArgumentException
- ifinitialArraySize
is negative
newArrayListWithExpectedSize
public static <E> ArrayList<E> newArrayListWithExpectedSize(int estimatedSize)
Creates anArrayList
instance to holdestimatedSize
elements, plus an unspecified amount of padding; you almost certainly mean to callnewArrayListWithCapacity(int)
(see that method for further advice on usage).Note: This method will soon be deprecated. Even in the rare case that you do want some amount of padding, it's best if you choose your desired amount explicitly.
- 参数:
-
estimatedSize
- an estimate of the eventualList.size()
of the new list - 返回:
-
a new, empty
ArrayList
, sized appropriately to hold the estimated number of elements - 抛出:
-
IllegalArgumentException
- ifestimatedSize
is negative
checkNotNull
public static <T> T checkNotNull(T reference)
Ensures that an object reference passed as a parameter to the calling method is not null.- 参数:
-
reference
- an object reference - 返回:
- the non-null reference that was validated
- 抛出:
-
NullPointerException
- ifreference
is null
Copyright © 2018–2021 Alibaba Group. All rights reserved.