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

How to use
add
method
in
java.util.List

Best Java code snippets using java.util.List.add (Showing top 20 results out of 433,485)

Refine searchRefine arrow

  • List.size
  • List.get
  • ArrayList.<init>
  • Map.put
  • Map.get
  • List.toArray
  • List.isEmpty
  • PrintStream.println
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: 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: square/okhttp

@Override public List<InetAddress> lookup(String hostname) throws UnknownHostException {
 requestedHosts.add(hostname);
 List<InetAddress> result = hostAddresses.get(hostname);
 if (result != null) return result;
 throw new UnknownHostException();
}
origin: stackoverflow.com

 List<String> strings = new ArrayList<String>()
strings.add("lol");
strings.add("cat");

Collections.sort(strings);
for (String s : strings) {
  System.out.println(s);
}
// Prints out "cat" and "lol"
origin: ReactiveX/RxJava

@Test
public void startWithIterable() {
  List<String> li = new ArrayList<String>();
  li.add("alpha");
  li.add("beta");
  List<String> values = Observable.just("one", "two").startWith(li).toList().blockingGet();
  assertEquals("alpha", values.get(0));
  assertEquals("beta", values.get(1));
  assertEquals("one", values.get(2));
  assertEquals("two", values.get(3));
}
origin: jenkinsci/jenkins

public RenderOnDemandClosure(JellyContext context, String attributesToCapture) {
  List<Script> bodyStack = new ArrayList<Script>();
  for (JellyContext c = context; c!=null; c=c.getParent()) {
    Script script = (Script) c.getVariables().get("org.apache.commons.jelly.body");
    if(script!=null) bodyStack.add(script);
  }
  this.bodyStack = bodyStack.toArray(new Script[bodyStack.size()]);
  assert !bodyStack.isEmpty();    // there must be at least one, which is the direct child of <l:renderOnDemand>
  Map<String,Object> variables = new HashMap<String, Object>();
  for (String v : Util.fixNull(attributesToCapture).split(","))
    variables.put(v.intern(),context.getVariable(v));
  // capture the current base of context for descriptors
  currentDescriptorByNameUrl = Descriptor.getCurrentDescriptorByNameUrl();
  this.variables = PackedMap.of(variables);
  Set<String> _adjuncts = AdjunctsInPage.get().getIncluded();
  this.adjuncts = new String[_adjuncts.size()];
  int i = 0;
  for (String adjunct : _adjuncts) {
    this.adjuncts[i++] = adjunct.intern();
  }
}
origin: spring-projects/spring-framework

@SuppressWarnings("unchecked")
IEEE() {
  officers.put("president",pupin);
  List linv = new ArrayList();
  linv.add(tesla);
  officers.put("advisors",linv);
  Members2.add(tesla);
  Members2.add(pupin);
  reverse.add(officers);
}
origin: spring-projects/spring-framework

@Override
public ResponseSpec onStatus(Predicate<HttpStatus> statusPredicate,
    Function<ClientResponse, Mono<? extends Throwable>> exceptionFunction) {
  if (this.statusHandlers.size() == 1 && this.statusHandlers.get(0) == DEFAULT_STATUS_HANDLER) {
    this.statusHandlers.clear();
  }
  this.statusHandlers.add(new StatusHandler(statusPredicate,
      (clientResponse, request) -> exceptionFunction.apply(clientResponse)));
  return this;
}
origin: ReactiveX/RxJava

@Override
public V put(K key, V value) {
  list.remove(key);
  V v;
  if (maxSize > 0 && list.size() == maxSize) {
    //remove first
    K k = list.get(0);
    list.remove(0);
    v = map.remove(k);
  } else {
    v = null;
  }
  list.add(key);
  V result = map.put(key, value);
  if (v != null) {
    try {
      evictedListener.accept(v);
    } catch (Exception e) {
      throw new RuntimeException(e);
    }
  }
  return result;
}
origin: apache/flink

private void processInsert(Row row) {
  // limit the materialized table
  if (materializedTable.size() - validRowPosition >= maxRowCount) {
    cleanUp();
  }
  materializedTable.add(row);
  rowPositionCache.put(row, materializedTable.size() - 1);
}
origin: square/okhttp

/**
 * Removes a path segment. When this method returns the last segment is always "", which means
 * the encoded path will have a trailing '/'.
 *
 * <p>Popping "/a/b/c/" yields "/a/b/". In this case the list of path segments goes from ["a",
 * "b", "c", ""] to ["a", "b", ""].
 *
 * <p>Popping "/a/b/c" also yields "/a/b/". The list of path segments goes from ["a", "b", "c"]
 * to ["a", "b", ""].
 */
private void pop() {
 String removed = encodedPathSegments.remove(encodedPathSegments.size() - 1);
 // Make sure the path ends with a '/' by either adding an empty string or clearing a segment.
 if (removed.isEmpty() && !encodedPathSegments.isEmpty()) {
  encodedPathSegments.set(encodedPathSegments.size() - 1, "");
 } else {
  encodedPathSegments.add("");
 }
}
origin: spring-projects/spring-framework

@Test
public void testGenericTypeNestingListOfMapOfInteger() throws Exception {
  List<Map<String, String>> list = new LinkedList<>();
  Map<String, String> map = new HashMap<>();
  map.put("testKey", "5");
  list.add(map);
  NestedGenericCollectionBean gb = new NestedGenericCollectionBean();
  BeanWrapper bw = new BeanWrapperImpl(gb);
  bw.setPropertyValue("listOfMapOfInteger", list);
  Object obj = gb.getListOfMapOfInteger().get(0).get("testKey");
  assertTrue(obj instanceof Integer);
  assertEquals(5, ((Integer) obj).intValue());
}
origin: spring-projects/spring-framework

@Test
public void testGenericListOfMaps() throws MalformedURLException {
  GenericBean<String> gb = new GenericBean<>();
  List<Map<Integer, Long>> list = new LinkedList<>();
  list.add(new HashMap<>());
  gb.setListOfMaps(list);
  BeanWrapper bw = new BeanWrapperImpl(gb);
  bw.setPropertyValue("listOfMaps[0][10]", new Long(5));
  assertEquals(new Long(5), bw.getPropertyValue("listOfMaps[0][10]"));
  assertEquals(new Long(5), gb.getListOfMaps().get(0).get(10));
}
origin: google/guava

/** Regression test for bug found. */
public void testCorrectOrdering_regression() {
 MinMaxPriorityQueue<Integer> q = MinMaxPriorityQueue.create(ImmutableList.of(3, 5, 1, 4, 7));
 List<Integer> expected = ImmutableList.of(1, 3, 4, 5, 7);
 List<Integer> actual = new ArrayList<>(5);
 for (int i = 0; i < expected.size(); i++) {
  actual.add(q.pollFirst());
 }
 assertEquals(expected, actual);
}
origin: ReactiveX/RxJava

private List<String> list(String... args) {
  List<String> list = new ArrayList<String>();
  for (String arg : args) {
    list.add(arg);
  }
  return list;
}
origin: spring-projects/spring-framework

@Override
public void set(K key, @Nullable V value) {
  List<V> values = new LinkedList<>();
  values.add(value);
  this.targetMap.put(key, values);
}
origin: spring-projects/spring-framework

protected HandshakeInterceptor[] getInterceptors() {
  List<HandshakeInterceptor> interceptors = new ArrayList<>(this.interceptors.size() + 1);
  interceptors.addAll(this.interceptors);
  interceptors.add(new OriginHandshakeInterceptor(this.allowedOrigins));
  return interceptors.toArray(new HandshakeInterceptor[0]);
}
origin: stackoverflow.com

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

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

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

  /* snip */

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

  System.out.println(System.currentTimeMillis() - st);
 }
}
origin: spring-projects/spring-framework

@Test
public void sortInstancesWithPriority() {
  List<Object> list = new ArrayList<>();
  list.add(new B2());
  list.add(new A2());
  AnnotationAwareOrderComparator.sort(list);
  assertTrue(list.get(0) instanceof A2);
  assertTrue(list.get(1) instanceof B2);
}
origin: spring-projects/spring-framework

  C() {
    ls = new ArrayList<>();
    ls.add("abc");
    ls.add("def");
    as = new String[] { "abc", "def" };
    ms = new HashMap<>();
    ms.put("abc", "xyz");
    ms.put("def", "pqr");
  }
}
java.utilListadd

Javadoc

Inserts the specified object into this List at the specified location. The object is inserted before the current element at the specified location. If the location is equal to the size of this List, the object is added at the end. If the location is smaller than the size of this List, then all elements beyond the specified location are moved by one position towards the end of the List.

Popular methods of List

  • 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
  • toArray
    Returns an array containing all elements contained in this List. If the specified array is large eno
  • 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
  • getSharedPreferences (Context)
  • onRequestPermissionsResult (Fragment)
  • getSystemService (Context)
  • Pointer (com.sun.jna)
    An abstraction for a native pointer data type. A Pointer instance represents, on the Java side, a na
  • Color (java.awt)
    The Color class is used to encapsulate colors in the default sRGB color space or colors in arbitrary
  • GridLayout (java.awt)
    The GridLayout class is a layout manager that lays out a container's components in a rectangular gri
  • Selector (java.nio.channels)
    A controller for the selection of SelectableChannel objects. Selectable channels can be registered w
  • Permission (java.security)
    Legacy security code; do not use.
  • ArrayList (java.util)
    ArrayList is an implementation of List, backed by an array. All optional operations including adding
  • Top Vim plugins
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