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

How to use
toArray
method
in
java.util.ArrayList

Best Java code snippets using java.util.ArrayList.toArray (Showing top 20 results out of 38,970)

Refine searchRefine arrow

  • ArrayList.size
  • ArrayList.add
  • ArrayList.<init>
  • Iterator.hasNext
  • Iterator.next
  • ArrayList.get
origin: spring-projects/spring-framework

/**
 * Marshal the elements from the given enumeration into an array of the given type.
 * Enumeration elements must be assignable to the type of the given array. The array
 * returned will be a different instance than the array given.
 */
public static <A, E extends A> A[] toArray(Enumeration<E> enumeration, A[] array) {
  ArrayList<A> elements = new ArrayList<>();
  while (enumeration.hasMoreElements()) {
    elements.add(enumeration.nextElement());
  }
  return elements.toArray(array);
}
origin: apache/flink

@SuppressWarnings("unchecked")
public Class<? extends Comparable<?>>[] getTypes() {
  return this.types.toArray(new Class[this.types.size()]);
}

origin: redisson/redisson

/**
 * Returns exception chain starting from top up to root cause.
 */
public static Throwable[] getExceptionChain(Throwable throwable) {
  ArrayList<Throwable> list = new ArrayList<>();
  list.add(throwable);
  while ((throwable = throwable.getCause()) != null) {
    list.add(throwable);
  }
  Throwable[] result = new Throwable[list.size()];
  return list.toArray(result);
}
origin: stanfordnlp/CoreNLP

@Override
public Object[] toArray() {
 Iterator<E> iter = iterator();
 ArrayList<Object> al = new ArrayList<>();
 while (iter.hasNext()) {
  al.add(iter.next());
 }
 return al.toArray();
}
origin: redisson/redisson

public CtField[] getFields() {
  ArrayList alist = new ArrayList();
  getFields(alist, this);
  return (CtField[])alist.toArray(new CtField[alist.size()]);
}
origin: spring-projects/spring-framework

@Test // SPR-14988
public void getMappingOverridesConsumesFromTypeLevelAnnotation() throws Exception {
  RequestMappingInfo requestMappingInfo = assertComposedAnnotationMapping(RequestMethod.GET);
  assertArrayEquals(new MediaType[]{MediaType.ALL}, new ArrayList<>(
      requestMappingInfo.getConsumesCondition().getConsumableMediaTypes()).toArray());
}
origin: org.apache.lucene/lucene-core

 /** Builds a {@link MultiPhraseQuery}. */
 public MultiPhraseQuery build() {
  int[] positionsArray = new int[this.positions.size()];
  for (int i = 0; i < this.positions.size(); ++i) {
   positionsArray[i] = this.positions.get(i);
  }
  Term[][] termArraysArray = termArrays.toArray(new Term[termArrays.size()][]);
  return new MultiPhraseQuery(field, termArraysArray, positionsArray, slop);
 }
}
origin: apache/flink

  @Override
  public void reduce(Iterable<Tuple2<Long, Long>> values, Collector<Tuple2<Long, Long[]>> out) {
    neighbors.clear();
    Long id = 0L;
    for (Tuple2<Long, Long> n : values) {
      id = n.f0;
      neighbors.add(n.f1);
    }
    out.collect(new Tuple2<Long, Long[]>(id, neighbors.toArray(new Long[neighbors.size()])));
  }
}
origin: prestodb/presto

  public static <T> Collector<T, ?, Object[][]> toDataProvider()
  {
    return Collector.of(
        ArrayList::new,
        (builder, entry) -> builder.add(new Object[] {entry}),
        (left, right) -> {
          left.addAll(right);
          return left;
        },
        builder -> builder.toArray(new Object[][] {}));
  }
}
origin: apache/activemq

public Message[] getMessages() {
  ArrayList<Object> list = new ArrayList<Object>();
  for (Iterator<TxOperation> iter = operations.iterator(); iter.hasNext();) {
    TxOperation op = iter.next();
    if (op.operationType == TxOperation.ADD_OPERATION_TYPE) {
      list.add(op.data);
    }
  }
  Message rc[] = new Message[list.size()];
  list.toArray(rc);
  return rc;
}
origin: stackoverflow.com

 ArrayList<Integer> foo = new ArrayList<Integer>();
foo.add(1);
foo.add(1);
foo.add(2);
foo.add(3);
foo.add(5);
Integer[] bar = foo.toArray(new Integer[foo.size()]);
System.out.println("bar.length = " + bar.length);
origin: neo4j/neo4j

private AnyValue[] iterationAsArray()
{
  ArrayList<AnyValue> values = new ArrayList<>();
  int size = 0;
  for ( AnyValue value : this )
  {
    values.add( value );
    size++;
  }
  return values.toArray( new AnyValue[size] );
}
origin: apache/flink

public static void compareResultsByLinesInMemoryWithStrictOrder(String expectedResultStr,
                                String resultPath, String[] excludePrefixes) throws Exception {
  ArrayList<String> list = new ArrayList<>();
  readAllResultLines(list, resultPath, excludePrefixes, true);
  String[] result = list.toArray(new String[list.size()]);
  String[] expected = expectedResultStr.split("\n");
  Assert.assertEquals("Different number of lines in expected and obtained result.", expected.length, result.length);
  Assert.assertArrayEquals(expected, result);
}
origin: spring-projects/spring-framework

@Test // SPR-14988
public void getMappingOverridesConsumesFromTypeLevelAnnotation() throws Exception {
  RequestMappingInfo requestMappingInfo = assertComposedAnnotationMapping(RequestMethod.GET);
  assertArrayEquals(new MediaType[]{MediaType.ALL}, new ArrayList<>(
      requestMappingInfo.getConsumesCondition().getConsumableMediaTypes()).toArray());
}
origin: wildfly/wildfly

private static InterceptorList ofList(final ArrayList<EJBClientInterceptorInformation> value) {
  if (value.isEmpty()) {
    return EMPTY;
  } else if (value.size() == 1) {
    return value.get(0).getSingletonList();
  } else {
    return new InterceptorList(value.toArray(EJBClientInterceptorInformation.NO_INTERCEPTORS));
  }
}
origin: apache/flink

  @Override
  public void reduce(Iterable<Tuple2<Long, Long>> values, Collector<Tuple2<Long, Long[]>> out) {
    neighbors.clear();
    Long id = 0L;
    for (Tuple2<Long, Long> n : values) {
      id = n.f0;
      neighbors.add(n.f1);
    }
    out.collect(new Tuple2<Long, Long[]>(id, neighbors.toArray(new Long[neighbors.size()])));
  }
}
origin: google/ExoPlayer

/**
 * Returns the {@link DataSpec} instances passed to {@link #open(DataSpec)} since the last call to
 * this method.
 */
public final DataSpec[] getAndClearOpenedDataSpecs() {
 DataSpec[] dataSpecs = new DataSpec[openedDataSpecs.size()];
 openedDataSpecs.toArray(dataSpecs);
 openedDataSpecs.clear();
 return dataSpecs;
}
origin: apache/activemq

public MessageAck[] getAcks() {
  ArrayList<Object> list = new ArrayList<Object>();
  for (Iterator<TxOperation> iter = operations.iterator(); iter.hasNext();) {
    TxOperation op = iter.next();
    if (op.operationType == TxOperation.REMOVE_OPERATION_TYPE) {
      list.add(op.data);
    }
  }
  MessageAck rc[] = new MessageAck[list.size()];
  list.toArray(rc);
  return rc;
}
origin: libgdx/libgdx

/** @return an array containing all the public fields of this class and its super classes. See {@link Class#getFields()}. */
public Field[] getFields () {
  if (allFields == null) {
    ArrayList<Field> allFieldsList = new ArrayList<Field>();
    Type t = this;
    while (t != null) {
      for (Field f : t.fields) {
        if (f.isPublic) allFieldsList.add(f);
      }
      t = t.getSuperclass();
    }
    allFields = allFieldsList.toArray(new Field[allFieldsList.size()]);
  }
  return allFields;
}
origin: gocd/gocd

public GoTfsWorkspace[] queryWorkspaces(String workspaceName, String userName) {
  ArrayList<GoTfsWorkspace> goTfsWorkspaces = new ArrayList<>();
  Workspace[] workspaces = client.queryWorkspaces(workspaceName, userName, null);
  for (Workspace workspace : workspaces) {
    goTfsWorkspaces.add(new GoTfsWorkspace(workspace));
  }
  return goTfsWorkspaces.toArray(new GoTfsWorkspace[]{});
}
java.utilArrayListtoArray

Javadoc

Returns a new array containing all elements contained in this ArrayList.

Popular methods of ArrayList

  • <init>
  • add
  • size
    Returns the number of elements in this ArrayList.
  • get
    Returns the element at the specified position in this list.
  • addAll
    Adds the objects in the specified collection to this ArrayList.
  • remove
    Removes the first occurrence of the specified element from this list, if it is present. If the list
  • clear
    Removes all elements from this ArrayList, leaving it empty.
  • isEmpty
    Returns true if this list contains no elements.
  • iterator
    Returns an iterator over the elements in this list in proper sequence.The returned iterator is fail-
  • contains
    Searches this ArrayList for the specified object.
  • set
    Replaces the element at the specified position in this list with the specified element.
  • indexOf
    Returns the index of the first occurrence of the specified element in this list, or -1 if this list
  • set,
  • indexOf,
  • clone,
  • subList,
  • stream,
  • ensureCapacity,
  • trimToSize,
  • removeAll,
  • toString

Popular in Java

  • Start an intent from android
  • orElseThrow (Optional)
    Return the contained value, if present, otherwise throw an exception to be created by the provided s
  • scheduleAtFixedRate (ScheduledExecutorService)
  • getExternalFilesDir (Context)
  • BorderLayout (java.awt)
    A border layout lays out a container, arranging and resizing its components to fit in five regions:
  • GridLayout (java.awt)
    The GridLayout class is a layout manager that lays out a container's components in a rectangular gri
  • Proxy (java.net)
    This class represents proxy server settings. A created instance of Proxy stores a type and an addres
  • ByteBuffer (java.nio)
    A buffer for bytes. A byte buffer can be created in either one of the following ways: * #allocate
  • ArrayList (java.util)
    ArrayList is an implementation of List, backed by an array. All optional operations including adding
  • Filter (javax.servlet)
    A filter is an object that performs filtering tasks on either the request to a resource (a servlet o
  • Github Copilot alternatives
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