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

How to use
add
method
in
java.util.ArrayList

Best Java code snippets using java.util.ArrayList.add (Showing top 20 results out of 127,017)

Refine searchRefine arrow

  • ArrayList.<init>
  • ArrayList.size
  • ArrayList.get
  • ArrayList.toArray
  • PrintStream.println
canonical example by Tabnine

private void usingArrayList() {
 ArrayList<String> list = new ArrayList<>(Arrays.asList("cat", "cow", "dog"));
 list.add("fish");
 int size = list.size(); // size = 4
 list.set(size - 1, "horse"); // replacing the last element to "horse"
 String removed = list.remove(1); // removed = "cow"
 String second = list.get(1); // second = "dog"
}
origin: stackoverflow.com

 ArrayList<String> list = new ArrayList<String>();
list.add("A");
list.add("B");
list.add("C");
origin: stackoverflow.com

 ArrayList aList = new ArrayList();
//Add elements to ArrayList object
aList.add("1");
aList.add("2");
aList.add("3");
aList.add("4");
aList.add("5");
Collections.reverse(aList);
System.out.println("After Reverse Order, ArrayList Contains : " + aList);
origin: apache/incubator-dubbo

/**
 * Adds a list/map reference.
 */
@Override
public int addRef(Object ref) {
  if (_refs == null)
    _refs = new ArrayList();
  _refs.add(ref);
  return _refs.size() - 1;
}
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: stackoverflow.com

 class Test1 {
 public static void main(String[] s) {
  long st = System.currentTimeMillis();

  List<String> l0 = new ArrayList<String>() {{
   add("Hello");
   add("World!");
  }};

  List<String> l1 = new ArrayList<String>() {{
   add("Hello");
   add("World!");
  }};

  /* snip */

  List<String> l999 = new ArrayList<String>() {{
   add("Hello");
   add("World!");
  }};

  System.out.println(System.currentTimeMillis() - st);
 }
}
origin: apache/flink

/**
 * Increases the result vector component at the specified position by the specified delta.
 */
private void updateResultVector(int position, int delta) {
  // inflate the vector to contain the given position
  while (this.resultVector.size() <= position) {
    this.resultVector.add(0);
  }
  // increment the component value
  final int component = this.resultVector.get(position);
  this.resultVector.set(position, component + delta);
}
origin: spring-projects/spring-framework

@Test
public void testGenericListOfArrays() throws MalformedURLException {
  GenericBean<String> gb = new GenericBean<>();
  ArrayList<String[]> list = new ArrayList<>();
  list.add(new String[] {"str1", "str2"});
  gb.setListOfArrays(list);
  BeanWrapper bw = new BeanWrapperImpl(gb);
  bw.setPropertyValue("listOfArrays[0][1]", "str3 ");
  assertEquals("str3 ", bw.getPropertyValue("listOfArrays[0][1]"));
  assertEquals("str3 ", gb.getListOfArrays().get(0)[1]);
}
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: libgdx/libgdx

/**
 * Adds a body to the group
 * 
 * @param argBody
 */
public void addBody(Body argBody) {
 bodies.add(argBody);
 if (bodies.size() == 1) {
  bodyA = argBody;
 }
 if (bodies.size() == 2) {
  bodyB = argBody;
 }
}
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: 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: google/guava

 static <T> List<T> defensiveCopy(Iterable<T> iterable) {
  ArrayList<T> list = new ArrayList<T>();
  for (T element : iterable) {
   list.add(checkNotNull(element));
  }
  return list;
 }
}
origin: apache/incubator-dubbo

/**
 * Adds a list/map reference.
 */
@Override
public int addRef(Object ref) {
  if (_refs == null)
    _refs = new ArrayList();
  _refs.add(ref);
  return _refs.size() - 1;
}
origin: stackoverflow.com

 ArrayList<String> list = new ArrayList<String>();
list.add("one");
list.add("two");
list.add("three");

String listString = "";

for (String s : list)
{
  listString += s + "\t";
}

System.out.println(listString);
origin: ReactiveX/RxJava

  @Override
  public void accept(String s) {
    System.out.println(s);
    list.add(s);
  }
});
origin: redisson/redisson

private static void addLdcW(CodeAttribute.LdcEntry ldcs, ArrayList jumps) {
  int where = ldcs.where;
  LdcW ldcw = new LdcW(where, ldcs.index);
  int s = jumps.size();
  for (int i = 0; i < s; i++)
    if (where < ((Branch)jumps.get(i)).orgPos) {
      jumps.add(i, ldcw);
      return;
    }
  jumps.add(ldcw);
}
origin: spring-projects/spring-framework

@Test
public void testGenericListOfArraysWithElementConversion() throws MalformedURLException {
  GenericBean<String> gb = new GenericBean<>();
  ArrayList<String[]> list = new ArrayList<>();
  list.add(new String[] {"str1", "str2"});
  gb.setListOfArrays(list);
  BeanWrapper bw = new BeanWrapperImpl(gb);
  bw.registerCustomEditor(String.class, new StringTrimmerEditor(false));
  bw.setPropertyValue("listOfArrays[0][1]", "str3 ");
  assertEquals("str3", bw.getPropertyValue("listOfArrays[0][1]"));
  assertEquals("str3", gb.getListOfArrays().get(0)[1]);
}
origin: apache/flink

@Override
protected void verifyResultsWhenReScaling(ListSink sink, int startElementCounter, int endElementCounter) throws Exception {
  ArrayList<Integer> list = new ArrayList<>();
  for (int i = startElementCounter; i <= endElementCounter; i++) {
    list.add(i);
  }
  Collections.sort(sink.values);
  Assert.assertArrayEquals(list.toArray(), sink.values.toArray());
}
java.utilArrayListadd

Javadoc

Inserts the specified object into this ArrayList at the specified location. The object is inserted before any previous element at the specified location. If the location is equal to the size of this ArrayList, the object is added at the end.

Popular methods of ArrayList

  • <init>
  • size
    Returns the number of elements in this ArrayList.
  • get
    Returns the element at the specified position in this list.
  • toArray
    Returns an array containing all of the elements in this list in proper sequence (from first to last
  • 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
  • From CI to AI: The AI layer in your organization
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