本文整理匯總了Java中java.util.List.toArray方法的典型用法代碼示例。如果您正苦於以下問題:Java List.toArray方法的具體用法?Java List.toArray怎麽用?Java List.toArray使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.util.List
的用法示例。
在下文中一共展示了List.toArray方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getDirectlyAndIndirectlyPresent
import java.util.List; //導入方法依賴的package包/類
/**
* Finds and returns all annotations in {@code annotations} matching
* the given {@code annoClass}.
*
* Apart from annotations directly present in {@code annotations} this
* method searches for annotations inside containers i.e. indirectly
* present annotations.
*
* The order of the elements in the array returned depends on the iteration
* order of the provided map. Specifically, the directly present annotations
* come before the indirectly present annotations if and only if the
* directly present annotations come before the indirectly present
* annotations in the map.
*
* @param annotations the {@code Map} in which to search for annotations
* @param annoClass the type of annotation to search for
*
* @return an array of instances of {@code annoClass} or an empty
* array if none were found
*/
public static <A extends Annotation> A[] getDirectlyAndIndirectlyPresent(
Map<Class<? extends Annotation>, Annotation> annotations,
Class<A> annoClass) {
List<A> result = new ArrayList<A>();
@SuppressWarnings("unchecked")
A direct = (A) annotations.get(annoClass);
if (direct != null)
result.add(direct);
A[] indirect = getIndirectlyPresent(annotations, annoClass);
if (indirect != null && indirect.length != 0) {
boolean indirectFirst = direct == null ||
containerBeforeContainee(annotations, annoClass);
result.addAll((indirectFirst ? 0 : 1), Arrays.asList(indirect));
}
@SuppressWarnings("unchecked")
A[] arr = (A[]) Array.newInstance(annoClass, result.size());
return result.toArray(arr);
}
示例2: concreteAliases
import java.util.List; //導入方法依賴的package包/類
public String[] concreteAliases(MetaData metaData, String concreteIndex) {
if (expandAliasesWildcards()) {
//for DELETE we expand the aliases
String[] indexAsArray = {concreteIndex};
ImmutableOpenMap<String, List<AliasMetaData>> aliasMetaData = metaData.findAliases(aliases, indexAsArray);
List<String> finalAliases = new ArrayList<>();
for (ObjectCursor<List<AliasMetaData>> curAliases : aliasMetaData.values()) {
for (AliasMetaData aliasMeta: curAliases.value) {
finalAliases.add(aliasMeta.alias());
}
}
return finalAliases.toArray(new String[finalAliases.size()]);
} else {
//for add we just return the current aliases
return aliases;
}
}
示例3: dealInclude
import java.util.List; //導入方法依賴的package包/類
protected Word[] dealInclude(Word[] wordObjects) throws Exception{
boolean isInclude = false;
StringBuffer includeFileName = new StringBuffer();
int point = 0;
List<Word> result = new ArrayList<Word>();
while(point <wordObjects.length ){
if(wordObjects[point].word.equals("include") ==true){
isInclude = true;
includeFileName.setLength(0);
}else if(isInclude == true && wordObjects[point].word.equals(";") ==true) {
isInclude = false;
Word[] childExpressWord = this.getExpressByName(includeFileName.toString());
childExpressWord = this.dealInclude(childExpressWord);
for(int i=0;i< childExpressWord.length;i++){
result.add(childExpressWord[i]);
}
}else if(isInclude == true){
includeFileName.append(wordObjects[point].word);
}else{
result.add(wordObjects[point]);
}
point = point + 1;
}
return result.toArray(new Word[0]);
}
示例4: getVideoQualityOptions
import java.util.List; //導入方法依賴的package包/類
@Override
protected CharSequence[] getVideoQualityOptions() {
List<CharSequence> videoQualities = new ArrayList<>();
if (getMinimumVideoDuration() > 0)
videoQualities.add(new VideoQualityOption(CameraConfiguration.MEDIA_QUALITY_AUTO, CameraHelper.getCamcorderProfile(CameraConfiguration.MEDIA_QUALITY_AUTO, getCameraController().getCurrentCameraId()), getMinimumVideoDuration()));
CamcorderProfile camcorderProfile = CameraHelper.getCamcorderProfile(CameraConfiguration.MEDIA_QUALITY_HIGH, getCameraController().getCurrentCameraId());
double videoDuration = CameraHelper.calculateApproximateVideoDuration(camcorderProfile, getVideoFileSize());
videoQualities.add(new VideoQualityOption(CameraConfiguration.MEDIA_QUALITY_HIGH, camcorderProfile, videoDuration));
camcorderProfile = CameraHelper.getCamcorderProfile(CameraConfiguration.MEDIA_QUALITY_MEDIUM, getCameraController().getCurrentCameraId());
videoDuration = CameraHelper.calculateApproximateVideoDuration(camcorderProfile, getVideoFileSize());
videoQualities.add(new VideoQualityOption(CameraConfiguration.MEDIA_QUALITY_MEDIUM, camcorderProfile, videoDuration));
camcorderProfile = CameraHelper.getCamcorderProfile(CameraConfiguration.MEDIA_QUALITY_LOW, getCameraController().getCurrentCameraId());
videoDuration = CameraHelper.calculateApproximateVideoDuration(camcorderProfile, getVideoFileSize());
videoQualities.add(new VideoQualityOption(CameraConfiguration.MEDIA_QUALITY_LOW, camcorderProfile, videoDuration));
CharSequence[] array = new CharSequence[videoQualities.size()];
videoQualities.toArray(array);
return array;
}
示例5: getInputs
import java.util.List; //導入方法依賴的package包/類
@Override
public RecipeElement[] getInputs()
{
List<RecipeElement> buf = new ArrayList<>();
for (RecipeElement ore : recipeItems)
{
if (ore != null)
{
buf.add(ore);
}
}
return buf.toArray(new RecipeElement[0]);
}
示例6: toArray
import java.util.List; //導入方法依賴的package包/類
private static <T> T[] toArray(Class <? super T > clazz, Iterable <? extends T > it)
{
List<T> list = Lists.<T>newArrayList();
for (T t : it)
{
list.add(t);
}
return (T[])((Object[])list.toArray(createArray(clazz, list.size())));
}
示例7: TabularDataSupport
import java.util.List; //導入方法依賴的package包/類
/**
* Creates an empty <tt>TabularDataSupport</tt> instance whose open-type is <var>tabularType</var>,
* and whose underlying <tt>HashMap</tt> has the specified initial capacity and load factor.
*
* @param tabularType the <i>tabular type</i> describing this <tt>TabularData</tt> instance;
* cannot be null.
*
* @param initialCapacity the initial capacity of the HashMap.
*
* @param loadFactor the load factor of the HashMap
*
* @throws IllegalArgumentException if the initial capacity is less than zero,
* or the load factor is nonpositive,
* or the tabular type is null.
*/
public TabularDataSupport(TabularType tabularType, int initialCapacity, float loadFactor) {
// Check tabularType is not null
//
if (tabularType == null) {
throw new IllegalArgumentException("Argument tabularType cannot be null.");
}
// Initialize this.tabularType (and indexNamesArray for convenience)
//
this.tabularType = tabularType;
List<String> tmpNames = tabularType.getIndexNames();
this.indexNamesArray = tmpNames.toArray(new String[tmpNames.size()]);
// Since LinkedHashMap was introduced in SE 1.4, it's conceivable even
// if very unlikely that we might be the server of a 1.3 client. In
// that case you'll need to set this property. See CR 6334663.
String useHashMapProp = AccessController.doPrivileged(
new GetPropertyAction("jmx.tabular.data.hash.map"));
boolean useHashMap = "true".equalsIgnoreCase(useHashMapProp);
// Construct the empty contents HashMap
//
this.dataMap = useHashMap ?
new HashMap<Object,CompositeData>(initialCapacity, loadFactor) :
new LinkedHashMap<Object, CompositeData>(initialCapacity, loadFactor);
}
示例8: getRolesForComponent
import java.util.List; //導入方法依賴的package包/類
/** Get the list of Role names that have access to the specified component
* @param componentName The component name to get the roles for
* @return Returns an array of Strings, each entry is a role name.
* If no roles have access to the component an empty array (new String[] {}) will be returned,
* If all roles have access to the component 'null' will be returned
* @throws SecurityException if the component is invalid
*/
public static String[] getRolesForComponent(String componentName) {
Map<String, List<String>> index = getComponentRoleIndex();
if (index == null)
return null;
// Throw an exception if there is no entry for the component. This would mean an invalid component.
if (!index.containsKey(componentName))
throw new SecurityException("PolicyManager could not find component '" + componentName + "'");
// Convert the extracted list to an array
List<String> l = index.get(componentName);
return l != null ? l.toArray(new String[l.size()]) : null;
}
示例9: fromList
import java.util.List; //導入方法依賴的package包/類
public void fromList(List<Float> lb) {
if(lb==null || lb.size()==0)
return;
Float ab[] = lb.toArray(new Float[0]);
float a[] = new float[ab.length];
for(int i=0; i<ab.length; i++)
a[i] = ab[i];
fromArray(a);
}
示例10: collectRefCursorParameters
import java.util.List; //導入方法依賴的package包/類
/**
* Collects any parameter registrations which indicate a REF_CURSOR parameter type/mode.
*
* @return The collected REF_CURSOR type parameters.
*/
public ParameterRegistrationImplementor[] collectRefCursorParameters() {
final List<ParameterRegistrationImplementor> refCursorParams = new ArrayList<ParameterRegistrationImplementor>();
for ( ParameterRegistrationImplementor param : registeredParameters ) {
if ( param.getMode() == ParameterMode.REF_CURSOR ) {
refCursorParams.add( param );
}
}
return refCursorParams.toArray( new ParameterRegistrationImplementor[refCursorParams.size()] );
}
示例11: getMethodValuesWithSubQueries
import java.util.List; //導入方法依賴的package包/類
private Object[] getMethodValuesWithSubQueries(SQLMethodInvokeExpr method) throws SqlParseException {
List<Object> values = new ArrayList<>();
for (SQLExpr innerExpr : method.getParameters()) {
if (innerExpr instanceof SQLQueryExpr) {
Select select = sqlParser.parseSelect((MySqlSelectQueryBlock) ((SQLQueryExpr) innerExpr).getSubQuery().getQuery());
values.add(new SubQueryExpression(select));
} else if (innerExpr instanceof SQLTextLiteralExpr) {
values.add(((SQLTextLiteralExpr) innerExpr).getText());
} else {
values.add(innerExpr);
}
}
return values.toArray();
}
示例12: concatenating
import java.util.List; //導入方法依賴的package包/類
/**
* Returns a hash function which computes its hash code by concatenating the hash codes of the
* underlying hash functions together. This can be useful if you need to generate hash codes of a
* specific length.
*
* <p>For example, if you need 1024-bit hash codes, you could join two {@link Hashing#sha512} hash
* functions together: {@code Hashing.concatenating(Hashing.sha512(), Hashing.sha512())}.
*
* @since 19.0
*/
public static HashFunction concatenating(Iterable<HashFunction> hashFunctions) {
checkNotNull(hashFunctions);
// We can't use Iterables.toArray() here because there's no hash->collect dependency
List<HashFunction> list = new ArrayList<HashFunction>();
for (HashFunction hashFunction : hashFunctions) {
list.add(hashFunction);
}
checkArgument(list.size() > 0, "number of hash functions (%s) must be > 0", list.size());
return new ConcatenatedHashFunction(list.toArray(new HashFunction[0]));
}
示例13: getCacheList
import java.util.List; //導入方法依賴的package包/類
@Override
public String[] getCacheList(String ssid, String lastUpdate)
{
try
{
authenticate(ssid);
final List<String> l = remoteCachingService.getCacheList(lastUpdate);
return l.toArray(new String[l.size()]);
}
catch( final Exception ex )
{
throw new RuntimeException(ex);
}
}
示例14: getActions
import java.util.List; //導入方法依賴的package包/類
@Override
public Action[] getActions(boolean context) {
List<? extends Action> actionsForPath = Utilities.actionsForPath("Android/ADB/EmulatorDevice");
return actionsForPath.toArray(new Action[actionsForPath.size()]);
}
示例15: getFiles
import java.util.List; //導入方法依賴的package包/類
/**
* Returns an array of FTPFile objects containing the whole list of
* files returned by the server as read by this object's parser.
* The files are filtered before being added to the array.
*
* @param filter FTPFileFilter, must not be <code>null</code>.
*
* @return an array of FTPFile objects containing the whole list of
* files returned by the server as read by this object's parser.
* <p><b>
* NOTE:</b> This array may contain null members if any of the
* individual file listings failed to parse. The caller should
* check each entry for null before referencing it, or use the
* a filter such as {@link org.apache.commons.net.ftp.FTPFileFilters#NON_NULL} which does not
* allow null entries.
* @since 2.2
* @exception java.io.IOException - not ever thrown, may be removed in a later release
*/
public FTPFile[] getFiles(FTPFileFilter filter)
throws IOException // TODO remove; not actually thrown
{
List<FTPFile> tmpResults = new ArrayList<FTPFile>();
Iterator<String> iter = this.entries.iterator();
while (iter.hasNext()) {
String entry = iter.next();
FTPFile temp = this.parser.parseFTPEntry(entry);
if (filter.accept(temp)){
tmpResults.add(temp);
}
}
return tmpResults.toArray(new FTPFile[tmpResults.size()]);
}