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

How to use
get
method
in
java.util.ArrayList

Best Java code snippets using java.util.ArrayList.get (Showing top 20 results out of 60,966)

Refine searchRefine arrow

  • ArrayList.size
  • ArrayList.add
  • ArrayList.<init>
  • PrintStream.println
  • ArrayList.remove
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

 @Test(expected=IndexOutOfBoundsException.class)
public void testIndexOutOfBoundsException() {
  ArrayList emptyList = new ArrayList();
  Object o = emptyList.get(0);
}
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: libgdx/libgdx

  public void mouseDragged (MouseEvent event) {
    if (dragIndex == -1 || dragIndex == 0 || dragIndex == percentages.size() - 1) return;
    float percent = (event.getX() - gradientX) / (float)gradientWidth;
    percent = Math.max(percent, percentages.get(dragIndex - 1) + 0.01f);
    percent = Math.min(percent, percentages.get(dragIndex + 1) - 0.01f);
    percentages.set(dragIndex, percent);
    repaint();
  }
});
origin: stackoverflow.com

 ViewPager pager = /* get my ViewPager */;
// assume this actually has stuff in it
final ArrayList<String> titles = new ArrayList<String>();

FragmentManager fm = getSupportFragmentManager();
pager.setAdapter(new FragmentStatePagerAdapter(fm) {
  public int getCount() {
    return titles.size();
  }

  public Fragment getItem(int position) {
    MyFragment fragment = new MyFragment();
    fragment.setTitle(titles.get(position));
    return fragment;
  }

  public int getItemPosition(Object item) {
    MyFragment fragment = (MyFragment)item;
    String title = fragment.getTitle();
    int position = titles.indexOf(title);

    if (position >= 0) {
      return position;
    } else {
      return POSITION_NONE;
    }
  }
});
origin: scouter-project/scouter

public void printCRUD() {
  do {
    System.out.print("type:" + sqlNode.type.toString() + "-->");
    for (int i = 0; i < sqlNode.tableList.size(); i++) {
      System.out.print(sqlNode.tableList.get(i) + " ");
    }
    System.out.println();
    sqlNode = sqlNode.nextNode;
  } while (sqlNode != null);
}
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: 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: stanfordnlp/CoreNLP

protected ArrayList<Integer> scanForPronouns(ArrayList<Pair<Integer, Integer>> nonQuoteRuns) {
 ArrayList<Integer> pronounList = new ArrayList<>();
 for(int run_index = 0; run_index < nonQuoteRuns.size(); run_index++)
  pronounList.addAll(scanForPronouns(nonQuoteRuns.get(run_index)));
 return pronounList;
}
origin: typ0520/fastdex

@Test
public void testDiff2() throws Throwable {
  if (!isDir(source_set1) || !isDir(source_set2) || !isDir(source_set11) || !isDir(source_set22)) {
    System.err.println("Test-env not init!!");
    return;
  }
  SourceSetSnapshoot now = new SourceSetSnapshoot(new File(workDir),source_set1);
  now.serializeTo(new FileOutputStream(new File(workDir,"snapshoot.json")));
  SourceSetSnapshoot old = (SourceSetSnapshoot) SourceSetSnapshoot.load(new File(workDir,"snapshoot.json"),SourceSetSnapshoot.class);
  JavaDirectorySnapshoot javaDirectorySnapshoot = new ArrayList<>(old.directorySnapshootSet).get(0);
  FileNode fileNode = new ArrayList<>(javaDirectorySnapshoot.nodes).get(0);
  fileNode.lastModified = System.currentTimeMillis();
  SourceSetDiffResultSet resultSet = (SourceSetDiffResultSet) now.diff(old);
  assertEquals(resultSet.changedJavaFileDiffInfos.size(),1);
  System.out.println(resultSet);
}
origin: ksoichiro/Android-ObservableScrollView

private void removeFixedViewInfo(View v, ArrayList<FixedViewInfo> where) {
  int len = where.size();
  for (int i = 0; i < len; ++i) {
    FixedViewInfo info = where.get(i);
    if (info.view == v) {
      where.remove(i);
      break;
    }
  }
}
origin: rey5137/material

@Override
public void registerListener(OnThemeChangedListener listener) {
  boolean exist = false;
  for(int i = mListeners.size() - 1; i >= 0; i--){
    WeakReference<OnThemeChangedListener> ref = mListeners.get(i);
    if(ref.get() == null)
      mListeners.remove(i);
    else if(ref.get() == listener)
      exist = true;
  }
  if(!exist)
    mListeners.add(new WeakReference<>(listener));
}
origin: FudanNLP/fnlp

public void print() {
  int i;
  for (i = 1; i <= size; i++)
    System.out.println(scores[i] + " " +datas.get(i).toString());
  System.out.println();
}
origin: facebook/stetho

public synchronized boolean unregister(PathMatcher path, HttpHandler handler) {
 int index = mPathMatchers.indexOf(path);
 if (index >= 0) {
  if (handler == mHttpHandlers.get(index)) {
   mPathMatchers.remove(index);
   mHttpHandlers.remove(index);
   return true;
  }
 }
 return false;
}
origin: daniulive/SmarterStreaming

private ArrayList<Map<String, Object>> getMapData(ArrayList<ArrayList<String>> list) {
  ArrayList<Map<String, Object>> data = new ArrayList<Map<String, Object>>();
  if (list == null)
    return data;
  for (int i = 0; i < list.size(); i++) {
    Map<String, Object> item = new HashMap<String, Object>();
    item.put("ItemFileName", list.get(i).get(0));
    data.add(item);
  }
  return data;
}
origin: google/ExoPlayer

private List<Cue> getDisplayCues() {
 List<Cue> displayCues = new ArrayList<>();
 for (int i = 0; i < cueBuilders.size(); i++) {
  Cue cue = cueBuilders.get(i).build();
  if (cue != null) {
   displayCues.add(cue);
  }
 }
 return displayCues;
}
origin: scouter-project/scouter

public void printCRUD() {
  do {
    System.out.print("type:" + sqlNode.type.toString() + "-->");
    for (int i = 0; i < sqlNode.tableList.size(); i++) {
      System.out.print(sqlNode.tableList.get(i) + " ");
    }
    System.out.println();
    sqlNode = sqlNode.nextNode;
  } while (sqlNode != null);
}
origin: spring-projects/spring-framework

  @Test(expected = IndexOutOfBoundsException.class)
  public void verifyJUnitExpectedException() {
    new ArrayList<>().get(1);
  }
}
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/incubator-dubbo

@Override
State shift(Object type) {
  if (_state == TYPE) {
    if (type instanceof String) {
      _typeDefList.add((String) type);
    } else if (type instanceof Integer) {
      int iValue = (Integer) type;
      if (iValue >= 0 && iValue < _typeDefList.size())
        type = _typeDefList.get(iValue);
    }
    printObject("map " + type + " (#" + _refId + ")");
    _state = VALUE;
    return this;
  } else
    throw new IllegalStateException();
}
java.utilArrayListget

Javadoc

Returns the element at the specified position in this list.

Popular methods of ArrayList

  • <init>
  • add
  • size
    Returns the number of elements in this ArrayList.
  • 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 plugins for WebStorm
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