Tabnine Logo
List.toArray
Code IndexAdd Tabnine to your IDE (free)

How to use
toArray
method
in
java.util.List

Best Java code snippets using java.util.List.toArray (Showing top 20 results out of 135,711)

Refine searchRefine arrow

  • List.size
  • List.add
  • ArrayList.<init>
  • List.get
  • List.isEmpty
  • Arrays.asList
canonical example by Tabnine

private String[] makeArrayFromList(List<String> list, int maxSize) {
 if (maxSize < list.size()) {
  list = list.subList(0, maxSize);
 }
 return list.toArray(new String[0]);
}
origin: stackoverflow.com

 List<String> list = new ArrayList<String>();
//add some stuff
list.add("android");
list.add("apple");
String[] stringArray = list.toArray(new String[0]);
origin: square/okhttp

Headers(Builder builder) {
 this.namesAndValues = builder.namesAndValues.toArray(new String[builder.namesAndValues.size()]);
}
origin: stackoverflow.com

 List<String> stockList = new ArrayList<String>();
stockList.add("stock1");
stockList.add("stock2");

String[] stockArr = new String[stockList.size()];
stockArr = stockList.toArray(stockArr);

for(String s : stockArr)
  System.out.println(s);
origin: google/j2objc

public Callback[] getCallbacks()
{
  if (callbacks.size() == 0)
    return new Callback[0];
  if (callbacks.get(0) instanceof Callback) {
    return (Callback[])callbacks.toArray(new Callback[callbacks.size()]);
  } else {
    throw new IllegalStateException("getCallback returned classes, not callbacks; call getCallbackTypes instead");
  }
}
origin: spring-projects/spring-framework

private static Profiles merge(String expression, List<Profiles> elements, @Nullable Operator operator) {
  assertWellFormed(expression, !elements.isEmpty());
  if (elements.size() == 1) {
    return elements.get(0);
  }
  Profiles[] profiles = elements.toArray(new Profiles[0]);
  return (operator == Operator.AND ? and(profiles) : or(profiles));
}
origin: apache/kafka

public Header[] toArray() {
  return headers.isEmpty() ? Record.EMPTY_HEADERS : headers.toArray(new Header[headers.size()]);
}
origin: redisson/redisson

@Override
@SuppressWarnings("unchecked")
public List<Map<Object, Object>> decode(List<Object> parts, State state) {
  Map<Object, Object>[] res = parts.toArray(new Map[parts.size()]);
  return Arrays.asList(res);
}
origin: spring-projects/spring-framework

/**
 * Extract a filtered set of PropertyDescriptors from the given BeanWrapper,
 * excluding ignored dependency types or properties defined on ignored dependency interfaces.
 * @param bw the BeanWrapper the bean was created with
 * @return the filtered PropertyDescriptors
 * @see #isExcludedFromDependencyCheck
 */
protected PropertyDescriptor[] filterPropertyDescriptorsForDependencyCheck(BeanWrapper bw) {
  List<PropertyDescriptor> pds = new ArrayList<>(Arrays.asList(bw.getPropertyDescriptors()));
  pds.removeIf(this::isExcludedFromDependencyCheck);
  return pds.toArray(new PropertyDescriptor[0]);
}
origin: google/guava

/** Resets the contents of sortedMultiset to have entries a, c, for the navigation tests. */
@SuppressWarnings("unchecked")
// Needed to stop Eclipse whining
private void resetWithHole() {
 List<E> container = new ArrayList<E>();
 container.addAll(Collections.nCopies(a.getCount(), a.getElement()));
 container.addAll(Collections.nCopies(c.getCount(), c.getElement()));
 super.resetContainer(getSubjectGenerator().create(container.toArray()));
 sortedMultiset = (SortedMultiset<E>) getMultiset();
}
origin: ReactiveX/RxJava

@Test
public void testGroupByWithElementSelector() {
  Observable<String> source = Observable.just("one", "two", "three", "four", "five", "six");
  Observable<GroupedObservable<Integer, Integer>> grouped = source.groupBy(length, length);
  Map<Integer, Collection<Integer>> map = toMap(grouped);
  assertEquals(3, map.size());
  assertArrayEquals(Arrays.asList(3, 3, 3).toArray(), map.get(3).toArray());
  assertArrayEquals(Arrays.asList(4, 4).toArray(), map.get(4).toArray());
  assertArrayEquals(Arrays.asList(5).toArray(), map.get(5).toArray());
}
origin: spring-projects/spring-framework

/**
 * Get all declared methods on the leaf class and all superclasses.
 * Leaf class methods are included first.
 * @param leafClass the class to introspect
 * @throws IllegalStateException if introspection fails
 */
public static Method[] getAllDeclaredMethods(Class<?> leafClass) {
  final List<Method> methods = new ArrayList<>(32);
  doWithMethods(leafClass, methods::add);
  return methods.toArray(new Method[0]);
}
origin: google/guava

private static Object[] getParameterValues(Method method) {
 FreshValueGenerator paramValues = new FreshValueGenerator();
 final List<Object> passedArgs = Lists.newArrayList();
 for (Class<?> paramType : method.getParameterTypes()) {
  passedArgs.add(paramValues.generateFresh(paramType));
 }
 return passedArgs.toArray();
}
origin: spring-projects/spring-framework

/**
 * Return all configured {@link MappedInterceptor MappedInterceptors} as an array.
 * @return the array of {@link MappedInterceptor MappedInterceptors}, or {@code null} if none
 */
@Nullable
protected final MappedInterceptor[] getMappedInterceptors() {
  List<MappedInterceptor> mappedInterceptors = new ArrayList<>(this.adaptedInterceptors.size());
  for (HandlerInterceptor interceptor : this.adaptedInterceptors) {
    if (interceptor instanceof MappedInterceptor) {
      mappedInterceptors.add((MappedInterceptor) interceptor);
    }
  }
  return (!mappedInterceptors.isEmpty() ? mappedInterceptors.toArray(new MappedInterceptor[0]) : null);
}
origin: google/guava

public static <E> MinimalSet<E> ofClassAndContents(
  Class<? super E> type, E[] emptyArrayForContents, Iterable<? extends E> contents) {
 List<E> setContents = new ArrayList<E>();
 for (E e : contents) {
  if (!setContents.contains(e)) {
   setContents.add(e);
  }
 }
 return new MinimalSet<E>(type, setContents.toArray(emptyArrayForContents));
}
origin: spring-projects/spring-framework

/**
 * Return a TemplateLoader based on the given TemplateLoader list.
 * If more than one TemplateLoader has been registered, a FreeMarker
 * MultiTemplateLoader needs to be created.
 * @param templateLoaders the final List of TemplateLoader instances
 * @return the aggregate TemplateLoader
 */
@Nullable
protected TemplateLoader getAggregateTemplateLoader(List<TemplateLoader> templateLoaders) {
  switch (templateLoaders.size()) {
    case 0:
      logger.debug("No FreeMarker TemplateLoaders specified");
      return null;
    case 1:
      return templateLoaders.get(0);
    default:
      TemplateLoader[] loaders = templateLoaders.toArray(new TemplateLoader[0]);
      return new MultiTemplateLoader(loaders);
  }
}
origin: neo4j/neo4j

public WarningsHandler warningsHandler()
{
  if ( warningsHandlers.isEmpty() )
  {
    return WarningsHandler.NO_WARNINGS_HANDLER;
  }
  if ( warningsHandlers.size() == 1 )
  {
    return warningsHandlers.get( 0 );
  }
  return new WarningsHandler.Multiplex(
      warningsHandlers.toArray( new WarningsHandler[warningsHandlers.size()] ) );
}
origin: square/okhttp

@Override public Certificate[] getServerCertificates() throws SSLPeerUnverifiedException {
 Handshake handshake = handshake();
 if (handshake == null) return null;
 List<Certificate> result = handshake.peerCertificates();
 return !result.isEmpty() ? result.toArray(new Certificate[result.size()]) : null;
}
origin: redisson/redisson

@Override
@SuppressWarnings("unchecked")
public List<Map<Object, Object>> decode(List<Object> parts, State state) {
  Map<Object, Object>[] res = parts.toArray(new Map[parts.size()]);
  return Arrays.asList(res);
}
origin: square/okhttp

@Override
public void configureTlsExtensions(SSLSocket sslSocket, String hostname,
  List<Protocol> protocols) {
 try {
  SSLParameters sslParameters = sslSocket.getSSLParameters();
  List<String> names = alpnProtocolNames(protocols);
  setProtocolMethod.invoke(sslParameters,
    new Object[] {names.toArray(new String[names.size()])});
  sslSocket.setSSLParameters(sslParameters);
 } catch (IllegalAccessException | InvocationTargetException e) {
  throw new AssertionError("failed to set SSL parameters", e);
 }
}
java.utilListtoArray

Javadoc

Returns an array containing all elements contained in this List.

Popular methods of List

  • add
  • size
    Returns the number of elements in this List.
  • get
    Returns the element at the specified location in this List.
  • isEmpty
    Returns whether this List contains no elements.
  • addAll
  • contains
    Tests whether this List contains the specified object.
  • remove
    Removes the first occurrence of the specified object from this List.
  • iterator
    Returns an iterator on the elements of this List. The elements are iterated in the same order as the
  • clear
  • stream
  • forEach
  • set
    Replaces the element at the specified position in this list with the specified element (optional ope
  • forEach,
  • set,
  • subList,
  • indexOf,
  • equals,
  • hashCode,
  • removeAll,
  • listIterator,
  • sort

Popular in Java

  • Making http requests using okhttp
  • scheduleAtFixedRate (Timer)
  • startActivity (Activity)
  • getApplicationContext (Context)
  • SecureRandom (java.security)
    This class generates cryptographically secure pseudo-random numbers. It is best to invoke SecureRand
  • Timestamp (java.sql)
    A Java representation of the SQL TIMESTAMP type. It provides the capability of representing the SQL
  • LinkedHashMap (java.util)
    LinkedHashMap is an implementation of Map that guarantees iteration order. All optional operations a
  • Locale (java.util)
    Locale represents a language/country/variant combination. Locales are used to alter the presentatio
  • SortedMap (java.util)
    A map that has its keys ordered. The sorting is according to either the natural ordering of its keys
  • SSLHandshakeException (javax.net.ssl)
    The exception that is thrown when a handshake could not be completed successfully.
  • Top 12 Jupyter Notebook extensions
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now