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

How to use
set
method
in
java.util.ArrayList

Best Java code snippets using java.util.ArrayList.set (Showing top 20 results out of 13,239)

Refine searchRefine arrow

  • ArrayList.get
  • ArrayList.size
  • ArrayList.add
  • ArrayList.<init>
  • 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: 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: apache/zookeeper

private Value next() throws IOException {
  if (vIdx < vLen) {
    Value v = valList.get(vIdx);
    valList.set(vIdx, null);
    vIdx++;
    return v;
  } else {
    throw new IOException("Error in deserialization.");
  }
}

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: FudanNLP/fnlp

private void toList(ArrayList<List<String>> lists) {
  ArrayList<String> e = new ArrayList<String>();
  e.add(word);
  e.add(pos);
  if(parent==null){
    e.add(String.valueOf(-1));
    e.add("Root");
  }
  else{
    e.add(String.valueOf(parent.id));
    e.add(relation);
  }
  lists.set(id, e);
  for (int i = 0; i < leftChilds.size(); i++) {
    leftChilds.get(i).toList(lists);
  }
  for (int i = 0; i < rightChilds.size(); i++) {
    rightChilds.get(i).toList(lists);
  }
  
}
//错误
origin: apache/hbase

@Override
public synchronized E set(int index, E element) {
 ArrayList<E> newList = new ArrayList<>(list);
 E result = newList.set(index, element);
 Collections.sort(list, comparator);
 list = Collections.unmodifiableList(newList);
 return result;
}
origin: google/guava

@CollectionSize.Require(absent = CollectionSize.ZERO)
@CollectionFeature.Require(ALLOWS_NULL_VALUES)
public void testEquals_containingNull() {
 ArrayList<E> elements = new ArrayList<>(getSampleElements());
 elements.set(elements.size() / 2, null);
 collection = getSubjectGenerator().create(elements.toArray());
 List<E> other = new ArrayList<>(getSampleElements());
 assertFalse(
   "Two Lists should not be equal if exactly one of them has null at a given index.",
   getList().equals(other));
}
origin: apache/hbase

/**
 * @param index Index of the stripe we need.
 * @return A lazy stripe copy from current stripes.
 */
private final ArrayList<HStoreFile> getStripeCopy(int index) {
 List<HStoreFile> stripeCopy = this.stripeFiles.get(index);
 ArrayList<HStoreFile> result = null;
 if (stripeCopy instanceof ImmutableList<?>) {
  result = new ArrayList<>(stripeCopy);
  this.stripeFiles.set(index, result);
 } else {
  result = (ArrayList<HStoreFile>)stripeCopy;
 }
 return result;
}
origin: kilim/kilim

void setLabel(int pos, LabelNode l) {
  for (int i = pos - posToLabelMap.size() + 1; i >= 0; i--) {
    // pad with nulls ala perl
    posToLabelMap.add(null);
  }
  posToLabelMap.set(pos, l);
  labelToPosMap.put(l, pos);
}

origin: apache/hive

 void incr() {
  if (supportsStreaming) {
   rowNums.set(0,new IntWritable(nextRow++));
  } else {
   rowNums.add(new IntWritable(nextRow++));
  }
 }
}
origin: real-logic/agrona

/**
 * Removes element at index, but instead of copying all elements to the left, moves into the same slot the last
 * element. This avoids the copy costs, but spoils the list order. If index is the last element it is just removed.
 *
 * @param list  to be modified.
 * @param index to be removed.
 * @param <T>   element type.
 * @throws IndexOutOfBoundsException if index is out of bounds.
 */
public static <T> void fastUnorderedRemove(final ArrayList<T> list, final int index)
{
  final int lastIndex = list.size() - 1;
  if (index != lastIndex)
  {
    list.set(index, list.remove(lastIndex));
  }
  else
  {
    list.remove(index);
  }
}
origin: org.codehaus.jackson/jackson-mapper-asl

public JsonNode _set(int index, JsonNode value)
{
  if (_children == null || index < 0 || index >= _children.size()) {
    throw new IndexOutOfBoundsException("Illegal index "+index+", array size "+size());
  }
  return _children.set(index, value);
}
origin: apache/incubator-druid

public void set(int index, int value)
{
 int subListIndex = index / ALLOCATION_SIZE;
 if (subListIndex >= baseLists.size()) {
  for (int i = baseLists.size(); i <= subListIndex; ++i) {
   baseLists.add(null);
  }
 }
 int[] baseList = baseLists.get(subListIndex);
 if (baseList == null) {
  baseList = new int[ALLOCATION_SIZE];
  baseLists.set(subListIndex, baseList);
 }
 baseList[index % ALLOCATION_SIZE] = value;
 if (index > maxIndex) {
  maxIndex = index;
 }
}
origin: apache/hive

@Override
public SearchArgument build() {
 if (currentTree.size() != 1) {
  throw new IllegalArgumentException("Failed to end " +
    currentTree.size() + " operations.");
 }
 ExpressionTree optimized = pushDownNot(root);
 optimized = foldMaybe(optimized);
 optimized = flatten(optimized);
 optimized = convertToCNF(optimized);
 optimized = flatten(optimized);
 int leafReorder[] = new int[leaves.size()];
 Arrays.fill(leafReorder, -1);
 int newLeafCount = compactLeaves(optimized, 0, leafReorder);
 optimized = rewriteLeaves(optimized, leafReorder);
 ArrayList<PredicateLeaf> leafList = new ArrayList<>(newLeafCount);
 // expand list to correct size
 for(int i=0; i < newLeafCount; ++i) {
  leafList.add(null);
 }
 // build the new list
 for(Map.Entry<PredicateLeaf, Integer> elem: leaves.entrySet()) {
  int newLoc = leafReorder[elem.getValue()];
  if (newLoc != -1) {
   leafList.set(newLoc, elem.getKey());
  }
 }
 return new SearchArgumentImpl(optimized, leafList);
}
origin: apache/storm

public static <V> ArrayList<V> convertToArray(Map<Integer, V> srcMap, int start) {
  Set<Integer> ids = srcMap.keySet();
  Integer largestId = ids.stream().max(Integer::compareTo).get();
  int end = largestId - start;
  ArrayList<V> result = new ArrayList<>(Collections.nCopies(end + 1, null)); // creates array[largestId+1] filled with nulls
  for (Map.Entry<Integer, V> entry : srcMap.entrySet()) {
    int id = entry.getKey();
    if (id < start) {
      LOG.debug("Entry {} will be skipped it is too small {} ...", id, start);
    } else {
      result.set(id - start, entry.getValue());
    }
  }
  return result;
}
origin: google/guava

@CollectionSize.Require(absent = CollectionSize.ZERO)
public void testEquals_otherListWithDifferentElements() {
 ArrayList<E> other = new ArrayList<>(getSampleElements());
 other.set(other.size() / 2, getSubjectGenerator().samples().e3());
 assertFalse(
   "A List should not equal another List containing different elements.",
   getList().equals(other));
}
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: jMonkeyEngine/jmonkeyengine

public void setData(int index, ByteBuffer data) {
  if (index >= 0) {
    while (this.data.size() <= index) {
      this.data.add(null);
    }
    this.data.set(index, data);
    setUpdateNeeded();
  } else {
    throw new IllegalArgumentException("index must be greater than or equal to 0.");
  }
}
origin: apache/hive

 void addRank() {
  if (supportsStreaming) {
   rowNums.set(0, new IntWritable(currentRank));
  } else {
   rowNums.add(new IntWritable(currentRank));
  }
 }
}
origin: apache/zookeeper

public boolean done() {
  Value v = valList.get(vIdx);
  if ("/array".equals(v.getType())) {
    valList.set(vIdx, null);
    vIdx++;
    return true;
  } else {
    return false;
  }
}
public void incr() {}
java.utilArrayListset

Javadoc

Replaces the element at the specified location in this ArrayListwith the specified object.

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.
  • 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.
  • indexOf
    Returns the index of the first occurrence of the specified element in this list, or -1 if this list
  • contains,
  • 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 12 Jupyter Notebook extensions
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