Tabnine Logo
ArrayList.<init>
Code IndexAdd Tabnine to your IDE (free)

How to use
java.util.ArrayList
constructor

Best Java code snippets using java.util.ArrayList.<init> (Showing top 20 results out of 429,507)

Refine searchRefine arrow

  • List.add
  • ArrayList.add
  • PrintStream.println
  • List.size
  • List.get
  • ArrayList.size
  • ArrayList.get
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

 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: stackoverflow.com

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

 public class SortedList<E> extends AbstractList<E> {

  private ArrayList<E> internalList = new ArrayList<E>();

  // Note that add(E e) in AbstractList is calling this one
  @Override 
  public void add(int position, E e) {
    internalList.add(e);
    Collections.sort(internalList, null);
  }

  @Override
  public E get(int i) {
    return internalList.get(i);
  }

  @Override
  public int size() {
    return internalList.size();
  }

}
origin: square/okhttp

private List<String> percentDecode(List<String> list, boolean plusIsSpace) {
 int size = list.size();
 List<String> result = new ArrayList<>(size);
 for (int i = 0; i < size; i++) {
  String s = list.get(i);
  result.add(s != null ? percentDecode(s, plusIsSpace) : null);
 }
 return Collections.unmodifiableList(result);
}
origin: spring-projects/spring-framework

private static List<Element> prependWithSeparator(List<Element> elements) {
  List<Element> result = new ArrayList<>(elements);
  if (result.isEmpty() || !(result.get(0) instanceof Separator)) {
    result.add(0, SEPARATOR);
  }
  return Collections.unmodifiableList(result);
}
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: google/guava

public SortedSetSubsetTestSetGenerator(
  TestSortedSetGenerator<E> delegate, Bound to, Bound from) {
 this.to = to;
 this.from = from;
 this.delegate = delegate;
 SortedSet<E> emptySet = delegate.create();
 this.comparator = emptySet.comparator();
 SampleElements<E> samples = delegate.samples();
 List<E> samplesList = new ArrayList<>(samples.asList());
 Collections.sort(samplesList, comparator);
 this.firstInclusive = samplesList.get(0);
 this.lastInclusive = samplesList.get(samplesList.size() - 1);
}
origin: spring-projects/spring-framework

public static List<MessagingAdviceBean> createFromList(List<ControllerAdviceBean> beans) {
  List<MessagingAdviceBean> result = new ArrayList<>(beans.size());
  for (ControllerAdviceBean bean : beans) {
    result.add(new MessagingControllerAdviceBean(bean));
  }
  return result;
}
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 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: 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

String[] arr = new String[1];
 arr[0] = "rohit";
 List<String> newList = Arrays.asList(arr);
 // Will throw `UnsupportedOperationException
 // newList.add("jain"); // Can't do this.
 ArrayList<String> updatableList = new ArrayList<String>();
 updatableList.addAll(newList); 
 updatableList.add("jain"); // OK this is fine. 
 System.out.println(newList);       // Prints [rohit]
 System.out.println(updatableList); //Prints [rohit, jain]
origin: stackoverflow.com

 // Substitute appropriate type.
ArrayList<...> a = new ArrayList<...>();

// Add elements to list.

// Generate an iterator. Start just after the last element.
ListIterator li = a.listIterator(a.size());

// Iterate in reverse.
while(li.hasPrevious()) {
 System.out.println(li.previous());
}
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: ReactiveX/RxJava

@Test
public void moreThanMaxWorkers() {
  final List<Worker> list = new ArrayList<Worker>();
  SchedulerMultiWorkerSupport mws = (SchedulerMultiWorkerSupport)Schedulers.computation();
  mws.createWorkers(max * 2, new WorkerCallback() {
    @Override
    public void onWorker(int i, Worker w) {
      list.add(w);
    }
  });
  assertEquals(max * 2, list.size());
}
origin: stackoverflow.com

 List<Person> people = new ArrayList<>();
people.add(new Person("Alice"));
people.add(new Person("Bob"));    
System.out.println(people);

// Prints [Alice, Bob]
origin: stackoverflow.com

 ArrayList<String> aList = new ArrayList<String>();
aList.add("One");
String element = aList.get(0); // no cast needed
System.out.println("Got one: " + element);
origin: square/okhttp

public static List<String> alpnProtocolNames(List<Protocol> protocols) {
 List<String> names = new ArrayList<>(protocols.size());
 for (int i = 0, size = protocols.size(); i < size; i++) {
  Protocol protocol = protocols.get(i);
  if (protocol == Protocol.HTTP_1_0) continue; // No HTTP/1.0 for ALPN.
  names.add(protocol.toString());
 }
 return names;
}
java.utilArrayList<init>

Javadoc

Constructs an empty vector so that its internal data array has size 10 and its standard capacity increment is zero.

Popular methods of ArrayList

  • add
  • 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
  • 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