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

How to use
subList
method
in
java.util.ArrayList

Best Java code snippets using java.util.ArrayList.subList (Showing top 20 results out of 4,275)

Refine searchRefine arrow

  • ArrayList.size
  • ArrayList.get
  • ArrayList.add
origin: stanfordnlp/CoreNLP

private static ArrayList<Word> cutLast(ArrayList<Word> s) {
 return new ArrayList<>(s.subList(0, s.size() - 1));
}
origin: airbnb/epoxy

@Override
public void onItemRangeRemoved(int positionStart, int itemCount) {
 if (itemCount == 0) {
  // no-op
  return;
 }
 List<ModelState> modelsToRemove =
   currentStateList.subList(positionStart, positionStart + itemCount);
 for (ModelState model : modelsToRemove) {
  currentStateMap.remove(model.id);
 }
 modelsToRemove.clear();
 // Update positions of affected items
 int size = currentStateList.size();
 for (int i = positionStart; i < size; i++) {
  currentStateList.get(i).position -= itemCount;
 }
}
origin: lealone/Lealone

public synchronized List<QueryEntry> getQueries() {
  // return a copy of the map so we don't have to
  // worry about external synchronization
  ArrayList<QueryEntry> list = new ArrayList<QueryEntry>();
  list.addAll(map.values());
  // only return the newest 100 entries
  Collections.sort(list, QUERY_ENTRY_COMPARATOR);
  return list.subList(0, Math.min(list.size(), maxQueryEntries));
}
origin: cmusphinx/sphinx4

/**
 * Copies a path
 */
private static void duplicatePath(int lastPathIndex, State fromState,
    State toState, ArrayList<ArrayList<State>> paths) {
  ArrayList<State> lastPath = paths.get(lastPathIndex);
  // copy the last path to a new one, from start to current state
  int fromIndex = lastPath.indexOf(fromState);
  int toIndex = lastPath.indexOf(toState);
  if (toIndex == -1) {
    toIndex = lastPath.size() - 1;
  }
  ArrayList<State> newPath = new ArrayList<State>(lastPath.subList(
      fromIndex, toIndex));
  paths.add(newPath);
}
origin: killme2008/Metamorphosis

  if (!matchLimited || matchList.size() < limit - 1) {
    final String match = input.subSequence(index, m.start()).toString();
    matchList.add(match);
    index = m.end();
  else if (matchList.size() == limit - 1) { // last one
    final String match = input.subSequence(index, input.length()).toString();
    matchList.add(match);
    index = m.end();
if (!matchLimited || matchList.size() < limit) {
  matchList.add(input.subSequence(index, input.length()).toString());
return matchList.subList(0, resultSize).toArray(result);
origin: google/guava

/**
 * For a given Enum type, creates an immutable map from each of the Enum's values to a
 * corresponding LockGraphNode, with the {@code allowedPriorLocks} and {@code
 * disallowedPriorLocks} prepopulated with nodes according to the natural ordering of the
 * associated Enum values.
 */
@VisibleForTesting
static <E extends Enum<E>> Map<E, LockGraphNode> createNodes(Class<E> clazz) {
 EnumMap<E, LockGraphNode> map = Maps.newEnumMap(clazz);
 E[] keys = clazz.getEnumConstants();
 final int numKeys = keys.length;
 ArrayList<LockGraphNode> nodes = Lists.newArrayListWithCapacity(numKeys);
 // Create a LockGraphNode for each enum value.
 for (E key : keys) {
  LockGraphNode node = new LockGraphNode(getLockName(key));
  nodes.add(node);
  map.put(key, node);
 }
 // Pre-populate all allowedPriorLocks with nodes of smaller ordinal.
 for (int i = 1; i < numKeys; i++) {
  nodes.get(i).checkAcquiredLocks(Policies.THROW, nodes.subList(0, i));
 }
 // Pre-populate all disallowedPriorLocks with nodes of larger ordinal.
 for (int i = 0; i < numKeys - 1; i++) {
  nodes.get(i).checkAcquiredLocks(Policies.DISABLED, nodes.subList(i + 1, numKeys));
 }
 return Collections.unmodifiableMap(map);
}
origin: lisawray/groupie

@Override
public void add(int position, @NonNull Group group) {
  super.add(position, group);
  children.add(position, group);
  final int notifyPosition = getHeaderItemCount() + getItemCount(children.subList(0, position));
  notifyItemRangeInserted(notifyPosition, group.getItemCount());
  refreshEmptyState();
}
origin: DataSketches/sketches-core

mem.putDouble(offset, weights_.get(i));
offset += Double.BYTES;
markBytes = MARK_SERDE.serializeToByteArray(marks_.subList(0, h_).toArray(new Boolean[0]));
mem.putByteArray(offset, markBytes, 0, markBytes.length);
offset += markBytes.length;
origin: stackoverflow.com

  if (!matchLimited || matchList.size() < limit - 1) {
    String match = input.subSequence(index, m.start()).toString();
    matchList.add(match);
    index = m.end();
  } else if (matchList.size() == limit - 1) { // last one
    String match = input.subSequence(index,
                     input.length()).toString();
    matchList.add(match);
    index = m.end();
if (!matchLimited || matchList.size() < limit)
  matchList.add(input.subSequence(index, input.length()).toString());
int resultSize = matchList.size();
if (limit == 0)
  while (resultSize > 0 && matchList.get(resultSize-1).equals(""))
    resultSize--;
String[] result = new String[resultSize];
return matchList.subList(0, resultSize).toArray(result);
origin: apache/geode

public static void exportDiskStore(ArrayList<String> args, String outputDir) {
 File out = outputDir == null ? new File(".") : new File(outputDir);
 if (!out.exists()) {
  out.mkdirs();
 }
 String dsName = args.get(0);
 File[] dirs = argsToFile(args.subList(1, args.size()));
 try {
  DiskStoreImpl.exportOfflineSnapshot(dsName, dirs, out);
 } catch (Exception ex) {
  throw new GemFireIOException(" disk-store=" + dsName + ": " + ex, ex);
 }
}
origin: stackoverflow.com

 public static <T> ArrayList<T[]> chunks(ArrayList<T> bigList,int n){
  ArrayList<T[]> chunks = new ArrayList<T[]>();

  for (int i = 0; i < bigList.size(); i += n) {
    T[] chunk = (T[])bigList.subList(i, Math.min(bigList.size(), i + n)).toArray();         
    chunks.add(chunk);
  }

  return chunks;
}
origin: google/j2objc

/**
 * For a given Enum type, creates an immutable map from each of the Enum's values to a
 * corresponding LockGraphNode, with the {@code allowedPriorLocks} and {@code
 * disallowedPriorLocks} prepopulated with nodes according to the natural ordering of the
 * associated Enum values.
 */
@VisibleForTesting
static <E extends Enum<E>> Map<E, LockGraphNode> createNodes(Class<E> clazz) {
 EnumMap<E, LockGraphNode> map = Maps.newEnumMap(clazz);
 E[] keys = clazz.getEnumConstants();
 final int numKeys = keys.length;
 ArrayList<LockGraphNode> nodes = Lists.newArrayListWithCapacity(numKeys);
 // Create a LockGraphNode for each enum value.
 for (E key : keys) {
  LockGraphNode node = new LockGraphNode(getLockName(key));
  nodes.add(node);
  map.put(key, node);
 }
 // Pre-populate all allowedPriorLocks with nodes of smaller ordinal.
 for (int i = 1; i < numKeys; i++) {
  nodes.get(i).checkAcquiredLocks(Policies.THROW, nodes.subList(0, i));
 }
 // Pre-populate all disallowedPriorLocks with nodes of larger ordinal.
 for (int i = 0; i < numKeys - 1; i++) {
  nodes.get(i).checkAcquiredLocks(Policies.DISABLED, nodes.subList(i + 1, numKeys));
 }
 return Collections.unmodifiableMap(map);
}
origin: apache/hbase

public void removeComponents(int startIndex) {
 List<List<HStoreFile>> subList = components.subList(startIndex, components.size());
 for (List<HStoreFile> entry : subList) {
  size -= entry.size();
 }
 assert size >= 0;
 subList.clear();
}
origin: naman14/Timber

public static List<Song> searchSongs(Context context, String searchString, int limit) {
  ArrayList<Song> result = getSongsForCursor(makeSongCursor(context, "title LIKE ?", new String[]{searchString + "%"}));
  if (result.size() < limit) {
    result.addAll(getSongsForCursor(makeSongCursor(context, "title LIKE ?", new String[]{"%_" + searchString + "%"})));
  }
  return result.size() < limit ? result : result.subList(0, limit);
}
origin: apache/hive

/**
 * ExpressionTypes.
 *
 */
public static enum ExpressionTypes {
 FIELD, JEXL
};
public static final String LLAP_OUTPUT_FORMAT_KEY = "Llap";
origin: apache/geode

public static void showDiskStoreMetadata(ArrayList<String> args) {
 String dsName = args.get(0);
 File[] dirs = argsToFile(args.subList(1, args.size()));
 try {
  DiskStoreImpl.dumpMetadata(dsName, dirs, showBuckets);
 } catch (Exception ex) {
  throw new GemFireIOException(" disk-store=" + dsName + ": " + ex, ex);
 }
}
origin: chrisk44/Hijacker

void addToView(){
  int index;
  if(this.device instanceof AP){
    index = i;
    if(i>0 && getComparatorForAP()!=null){
      index = findIndex(tiles.subList(0, i), this, getComparatorForAP());
    }
    i++;
  }else{
    index = tiles.size();
    if(tiles.size() - i > 0 && getComparatorForST()!=null){
      index = findIndex(tiles.subList(i, tiles.size()), this, getComparatorForST()) + i;
    }
  }
  tiles.add(index, this);
  adapter.insert(this, index);
  onCountsChanged();
}
static int findIndex(List<Tile> list, Tile tile, Comparator<Tile> comp){
origin: prestodb/presto

/**
 * For a given Enum type, creates an immutable map from each of the Enum's values to a
 * corresponding LockGraphNode, with the {@code allowedPriorLocks} and {@code
 * disallowedPriorLocks} prepopulated with nodes according to the natural ordering of the
 * associated Enum values.
 */
@VisibleForTesting
static <E extends Enum<E>> Map<E, LockGraphNode> createNodes(Class<E> clazz) {
 EnumMap<E, LockGraphNode> map = Maps.newEnumMap(clazz);
 E[] keys = clazz.getEnumConstants();
 final int numKeys = keys.length;
 ArrayList<LockGraphNode> nodes = Lists.newArrayListWithCapacity(numKeys);
 // Create a LockGraphNode for each enum value.
 for (E key : keys) {
  LockGraphNode node = new LockGraphNode(getLockName(key));
  nodes.add(node);
  map.put(key, node);
 }
 // Pre-populate all allowedPriorLocks with nodes of smaller ordinal.
 for (int i = 1; i < numKeys; i++) {
  nodes.get(i).checkAcquiredLocks(Policies.THROW, nodes.subList(0, i));
 }
 // Pre-populate all disallowedPriorLocks with nodes of larger ordinal.
 for (int i = 0; i < numKeys - 1; i++) {
  nodes.get(i).checkAcquiredLocks(Policies.DISABLED, nodes.subList(i + 1, numKeys));
 }
 return Collections.unmodifiableMap(map);
}
origin: com.h2database/h2

public synchronized List<QueryEntry> getQueries() {
  // return a copy of the map so we don't have to
  // worry about external synchronization
  ArrayList<QueryEntry> list = new ArrayList<>(map.values());
  // only return the newest 100 entries
  Collections.sort(list, QUERY_ENTRY_COMPARATOR);
  return list.subList(0, Math.min(list.size(), maxQueryEntries));
}
origin: bonnyfone/vectalign

ArrayList<PathParser.PathDataNode> transformTo = PathNodeUtils.transform(to, 0, true);
int fromSize = transformFrom.size();
int toSize = transformTo.size();
int min = Math.min(fromSize, toSize);
int numberOfSubAligns = (int) Math.max(1, min/2);
  startToIndex = i * toChunkSize;
  System.out.println("Subaligning FROM("+startFromIndex +","+endFromIndex+") - TO("+startToIndex +","+endToIndex+")");
  ArrayList<PathParser.PathDataNode>[] subAlign = doRawAlign(transformFrom.subList(startFromIndex, endFromIndex).toArray(new PathParser.PathDataNode[1]), transformTo.subList(startToIndex, endToIndex).toArray(new PathParser.PathDataNode[1]));
  finalFrom.addAll(subAlign[0]);
  finalTo.addAll(subAlign[1]);
java.utilArrayListsubList

Javadoc

Returns a view of the portion of this list between the specified fromIndex, inclusive, and toIndex, exclusive. (If fromIndex and toIndex are equal, the returned list is empty.) The returned list is backed by this list, so non-structural changes in the returned list are reflected in this list, and vice-versa. The returned list supports all of the optional list operations.

This method eliminates the need for explicit range operations (of the sort that commonly exist for arrays). Any operation that expects a list can be used as a range operation by passing a subList view instead of a whole list. For example, the following idiom removes a range of elements from a list:

 
list.subList(from, to).clear(); 
Similar idioms may be constructed for #indexOf(Object) and #lastIndexOf(Object), and all of the algorithms in the Collections class can be applied to a subList.

The semantics of the list returned by this method become undefined if the backing list (i.e., this list) is structurally modified in any way other than via the returned list. (Structural modifications are those that change the size of this list, or otherwise perturb it in such a fashion that iterations in progress may yield incorrect results.)

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.
  • set
    Replaces the element at the specified position in this list with the specified element.
  • contains,
  • set,
  • indexOf,
  • clone,
  • 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