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

How to use
subList
method
in
java.util.List

Best Java code snippets using java.util.List.subList (Showing top 20 results out of 40,509)

Refine searchRefine arrow

  • List.size
  • List.get
  • List.add
  • List.isEmpty
  • List.addAll
  • Arrays.asList
canonical example by Tabnine

private String[] makeArrayFromList(List<String> list, int maxSize) {
 if (maxSize < list.size()) {
  list = list.subList(0, maxSize);
 }
 return list.toArray(new String[0]);
}
origin: google/guava

@Override
<E> List<Entry<E>> expectedEntries(int targetEntry, List<Entry<E>> entries) {
 return entries.subList(targetEntry, entries.size());
}
origin: bumptech/glide

private static List<String> getComparableParameterNames(
  ExecutableElement element, boolean skipFirst) {
 List<? extends VariableElement> parameters = element.getParameters();
 if (skipFirst) {
  parameters = parameters.subList(1, parameters.size());
 }
 List<String> result = new ArrayList<>(parameters.size());
 for (VariableElement parameter : parameters) {
  result.add(parameter.asType().toString());
 }
 return result;
}
origin: google/guava

@CollectionSize.Require(absent = {ZERO})
public void testSubList_isEmpty() {
 List<E> list = getList();
 int size = getNumElements();
 for (List<E> subList :
   Arrays.asList(
     list.subList(0, size),
     list.subList(0, size - 1),
     list.subList(1, size),
     list.subList(0, 0),
     list.subList(size, size))) {
  assertEquals(subList.size() == 0, subList.isEmpty());
 }
}
origin: airbnb/lottie-android

@Override public void setContents(List<Content> contentsBefore, List<Content> contentsAfter) {
 // Do nothing with contents after.
 List<Content> myContentsBefore = new ArrayList<>(contentsBefore.size() + contents.size());
 myContentsBefore.addAll(contentsBefore);
 for (int i = contents.size() - 1; i >= 0; i--) {
  Content content = contents.get(i);
  content.setContents(myContentsBefore, contents.subList(0, i));
  myContentsBefore.add(content);
 }
}
origin: prestodb/presto

private static List<Integer> trimTrailing(List<Integer> codePoints, int codePointToTrim)
{
  int endIndex = codePoints.size();
  while (endIndex > 0 && codePoints.get(endIndex - 1) == codePointToTrim) {
    endIndex--;
  }
  return ImmutableList.copyOf(codePoints.subList(0, endIndex));
}
origin: google/guava

@CollectionSize.Require(absent = {ZERO, ONE})
public void testSubList_get() {
 List<E> list = getList();
 int size = getNumElements();
 List<E> copy = list.subList(0, size);
 List<E> head = list.subList(0, size - 1);
 List<E> tail = list.subList(1, size);
 assertEquals(list.get(0), copy.get(0));
 assertEquals(list.get(size - 1), copy.get(size - 1));
 assertEquals(list.get(1), tail.get(0));
 assertEquals(list.get(size - 1), tail.get(size - 2));
 assertEquals(list.get(0), head.get(0));
 assertEquals(list.get(size - 2), head.get(size - 2));
 for (List<E> subList : Arrays.asList(copy, head, tail)) {
  for (int index : Arrays.asList(-1, subList.size())) {
   try {
    subList.get(index);
    fail("expected IndexOutOfBoundsException");
   } catch (IndexOutOfBoundsException expected) {
   }
  }
 }
}
origin: square/picasso

Builder(Picasso picasso) {
 context = picasso.context;
 callFactory = picasso.callFactory;
 service = picasso.dispatcher.service;
 cache = picasso.cache;
 listener = picasso.listener;
 requestTransformers.addAll(picasso.requestTransformers);
 // See Picasso(). Removes internal request handlers added before and after custom handlers.
 int numRequestHandlers = picasso.requestHandlers.size();
 requestHandlers.addAll(picasso.requestHandlers.subList(2, numRequestHandlers - 6));
 defaultBitmapConfig = picasso.defaultBitmapConfig;
 indicatorsEnabled = picasso.indicatorsEnabled;
 loggingEnabled = picasso.loggingEnabled;
}
origin: stanfordnlp/CoreNLP

private void addMention(int beginIdx, int endIdx, IndexedWord headword, List<Mention> mentions, Set<IntPair> mentionSpanSet, Set<IntPair> namedEntitySpanSet, List<CoreLabel> sent, SemanticGraph basic, SemanticGraph enhanced) {
 IntPair mSpan = new IntPair(beginIdx, endIdx);
 if(!mentionSpanSet.contains(mSpan) && (!insideNE(mSpan, namedEntitySpanSet)) ) {
  int dummyMentionId = -1;
  Mention m = new Mention(dummyMentionId, beginIdx, endIdx, sent, basic, enhanced, new ArrayList<>(sent.subList(beginIdx, endIdx)));
  m.headIndex = headword.index()-1;
  m.headWord = sent.get(m.headIndex);
  m.headString = m.headWord.word().toLowerCase(Locale.ENGLISH);
  mentions.add(m);
  mentionSpanSet.add(mSpan);
 }
}
origin: stackoverflow.com

List<Integer> numbers = new ArrayList<Integer>(
   Arrays.asList(5,3,1,2,9,5,0,7)
 );
 List<Integer> head = numbers.subList(0, 4);
 List<Integer> tail = numbers.subList(4, 8);
 System.out.println(head); // prints "[5, 3, 1, 2]"
 System.out.println(tail); // prints "[9, 5, 0, 7]"
 Collections.sort(head);
 System.out.println(numbers); // prints "[1, 2, 3, 5, 9, 5, 0, 7]"
 tail.add(-1);
 System.out.println(numbers); // prints "[1, 2, 3, 5, 9, 5, 0, 7, -1]"
origin: google/guava

 @Override
 public List<T> next() {
  if (!hasNext()) {
   throw new NoSuchElementException();
  }
  Object[] array = new Object[size];
  int count = 0;
  for (; count < size && iterator.hasNext(); count++) {
   array[count] = iterator.next();
  }
  for (int i = count; i < size; i++) {
   array[i] = null; // for GWT
  }
  @SuppressWarnings("unchecked") // we only put Ts in it
  List<T> list = Collections.unmodifiableList((List<T>) Arrays.asList(array));
  return (pad || count == size) ? list : list.subList(0, count);
 }
};
origin: shekhargulati/99-problems

  private static <T> int _lengthRecursive(List<T> list, int i) {
    if (list.isEmpty()) {
      return i;
    }
    return _lengthRecursive(list.subList(1, list.size()), ++i);
  }
}
origin: google/guava

@ListFeature.Require(SUPPORTS_ADD_WITH_INDEX)
public void testSubList_subListAddAffectsOriginal() {
 List<E> subList = getList().subList(0, 0);
 subList.add(e3());
 expectAdded(0, e3());
}
origin: google/guava

@CollectionSize.Require(absent = {ZERO, ONE})
public void testSubList_ofSubListNonEmpty() {
 List<E> subList = getList().subList(0, 2).subList(1, 2);
 assertEquals(
   "subList(0, 2).subList(1, 2) "
     + "should be a single-element list of the element at index 1",
   Collections.singletonList(getOrderedElements().get(1)),
   subList);
}
origin: google/guava

/** Test throwing ConcurrentModificationException when a sublist's ancestor's delegate changes. */
public void testSublistConcurrentModificationException() {
 ListMultimap<String, Integer> multimap = create();
 multimap.putAll("foo", asList(1, 2, 3, 4, 5));
 List<Integer> list = multimap.get("foo");
 assertThat(multimap.get("foo")).containsExactly(1, 2, 3, 4, 5).inOrder();
 List<Integer> sublist = list.subList(0, 5);
 assertThat(sublist).containsExactly(1, 2, 3, 4, 5).inOrder();
 sublist.clear();
 assertTrue(sublist.isEmpty());
 multimap.put("foo", 6);
 try {
  sublist.isEmpty();
  fail("Expected ConcurrentModificationException");
 } catch (ConcurrentModificationException expected) {
 }
}
origin: google/guava

ToOptionalState combine(ToOptionalState other) {
 if (element == null) {
  return other;
 } else if (other.element == null) {
  return this;
 } else {
  if (extras == null) {
   extras = new ArrayList<>();
  }
  extras.add(other.element);
  if (other.extras != null) {
   this.extras.addAll(other.extras);
  }
  if (extras.size() > MAX_EXTRAS) {
   extras.subList(MAX_EXTRAS, extras.size()).clear();
   throw multiples(true);
  }
  return this;
 }
}
origin: prestodb/presto

  @Override
  public Type createType(TypeManager typeManager, List<TypeParameter> parameters)
  {
    checkArgument(parameters.size() >= 1, "Function type must have at least one parameter, got %s", parameters);
    checkArgument(
        parameters.stream().allMatch(parameter -> parameter.getKind() == ParameterKind.TYPE),
        "Expected only types as a parameters, got %s",
        parameters);
    List<Type> types = parameters.stream().map(TypeParameter::getType).collect(toList());

    return new FunctionType(types.subList(0, types.size() - 1), types.get(types.size() - 1));
  }
}
origin: skylot/jadx

public void addRecentFile(String filePath) {
  recentFiles.remove(filePath);
  recentFiles.add(0, filePath);
  int count = recentFiles.size();
  if (count > RECENT_FILES_COUNT) {
    recentFiles.subList(RECENT_FILES_COUNT, count).clear();
  }
  partialSync(settings -> settings.recentFiles = recentFiles);
}
origin: google/guava

@Override
<E> List<Entry<E>> expectedEntries(int targetEntry, List<Entry<E>> entries) {
 return entries.subList(targetEntry + 1, entries.size());
}
origin: stanfordnlp/CoreNLP

@Override
public List<E> objectsList() {
 List<E> result = new ArrayList<>();
 if (result.size() > backingIndexSize) {
  // we told you not to do this
  result.addAll(backingIndex.objectsList().subList(0, backingIndexSize));
 } else {
  result.addAll(backingIndex.objectsList());
 }
 result.addAll(spilloverIndex.objectsList());
 return Collections.unmodifiableList(result);
}
java.utilListsubList

Javadoc

Returns a List of the specified portion of this List from the given start index to the end index minus one. The returned List is backed by this List so changes to it are reflected by the other.

Popular methods of List

  • add
  • 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
  • stream,
  • forEach,
  • set,
  • indexOf,
  • equals,
  • hashCode,
  • removeAll,
  • listIterator,
  • sort

Popular in Java

  • Making http requests using okhttp
  • scheduleAtFixedRate (Timer)
  • startActivity (Activity)
  • getApplicationContext (Context)
  • SecureRandom (java.security)
    This class generates cryptographically secure pseudo-random numbers. It is best to invoke SecureRand
  • Timestamp (java.sql)
    A Java representation of the SQL TIMESTAMP type. It provides the capability of representing the SQL
  • LinkedHashMap (java.util)
    LinkedHashMap is an implementation of Map that guarantees iteration order. All optional operations a
  • Locale (java.util)
    Locale represents a language/country/variant combination. Locales are used to alter the presentatio
  • SortedMap (java.util)
    A map that has its keys ordered. The sorting is according to either the natural ordering of its keys
  • SSLHandshakeException (javax.net.ssl)
    The exception that is thrown when a handshake could not be completed successfully.
  • 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