Tabnine Logo
LinkedList
Code IndexAdd Tabnine to your IDE (free)

How to use
LinkedList
in
java.util

Best Java code snippets using java.util.LinkedList (Showing top 20 results out of 103,707)

canonical example by Tabnine

private void mappingWordsLength(List<String> wordsList) {
 Map<Integer, Set<String>> mapping = new HashMap<>();
 for (String word : wordsList) {
  mapping.computeIfAbsent(word.length(), HashSet::new).add(word);
 }
 List<Integer> lengths = new LinkedList<>(mapping.keySet());
 Collections.sort(lengths);
 lengths.forEach(n -> System.out.println(mapping.get(n).size() + " words with " + n + " chars"));
}
origin: google/guava

 @Override
 public List<Object> get() {
  return new LinkedList<>();
 }
}
origin: org.mockito/mockito-core

public static <T> LinkedList<T> filter(Collection<T> collection, Filter<T> filter) {
  LinkedList<T> filtered = new LinkedList<T>();
  for (T t : collection) {
    if (!filter.isOut(t)) {
      filtered.add(t);
    }
  }
  return filtered;
}
origin: log4j/log4j

public boolean isEmpty() {
 boolean empty = false;
 if (_categoryElements.size() == 0) {
  empty = true;
 }
 return (empty);
}
origin: org.mockito/mockito-core

public void removeLast() {
  //TODO: add specific test for synchronization of this block (it is tested by InvocationContainerImplTest at the moment)
  synchronized (invocations) {
    if (! invocations.isEmpty()) {
      invocations.removeLast();
    }
  }
}
origin: org.mockito/mockito-core

  public Object answer(InvocationOnMock invocation) throws Throwable {
    if (elements.size() == 1)
      return elements.get(0);
    else
      return elements.poll();
  }
}
origin: log4j/log4j

/**
 * Ensures that the MRU list will have a MaxSize.
 */
protected void setMaxSize(int maxSize) {
 if (maxSize < _mruFileList.size()) {
  for (int i = 0; i < _mruFileList.size() - maxSize; i++) {
   _mruFileList.removeLast();
  }
 }
 _maxSize = maxSize;
}
//--------------------------------------------------------------------------
origin: org.mockito/mockito-core

public void add(Invocation invocation) {
  synchronized (invocations) {
    invocations.add(invocation);
  }
}
origin: log4j/log4j

/**
 * Moves the the index to the top of the MRU List
 *
 * @param index The index to be first in the mru list
 */
public void moveToTop(int index) {
 _mruFileList.add(0, _mruFileList.remove(index));
}
origin: spring-projects/spring-framework

/**
 * Create a new buffer and store it in the LinkedList
 * <p>Adds a new buffer that can store at least {@code minCapacity} bytes.
 */
private void addBuffer(int minCapacity) {
  if (this.buffers.peekLast() != null) {
    this.alreadyBufferedSize += this.index;
    this.index = 0;
  }
  if (this.nextBlockSize < minCapacity) {
    this.nextBlockSize = nextPowerOf2(minCapacity);
  }
  this.buffers.add(new byte[this.nextBlockSize]);
  this.nextBlockSize *= 2;  // block size doubles each time
}
origin: log4j/log4j

/**
 * Adds an object to the mru.
 */
protected void setMRU(Object o) {
 int index = _mruFileList.indexOf(o);
 if (index == -1) {
  _mruFileList.add(0, o);
  setMaxSize(_maxSize);
 } else {
  moveToTop(index);
 }
}
origin: spring-projects/spring-framework

/**
 * Returns a tree-style representation of the current {@code ParseState}.
 */
@Override
public String toString() {
  StringBuilder sb = new StringBuilder();
  for (int x = 0; x < this.state.size(); x++) {
    if (x > 0) {
      sb.append('\n');
      for (int y = 0; y < x; y++) {
        sb.append(TAB);
      }
      sb.append("-> ");
    }
    sb.append(this.state.get(x));
  }
  return sb.toString();
}
origin: spring-projects/spring-framework

  @Override
  public Reference<K, V> pollForPurge() {
    if (TestWeakConcurrentCache.this.disableTestHooks) {
      return super.pollForPurge();
    }
    return TestWeakConcurrentCache.this.queue.isEmpty() ? null : TestWeakConcurrentCache.this.queue.removeFirst();
  }
};
origin: spring-projects/spring-framework

@SuppressWarnings("unchecked")
@Nullable
private <T> T getLastBuilder(Class<T> builderClass) {
  if (!this.builders.isEmpty()) {
    PathComponentBuilder last = this.builders.getLast();
    if (builderClass.isInstance(last)) {
      return (T) last;
    }
  }
  return null;
}
origin: hankcs/HanLP

/**
 * 获取最长的后缀
 * @param word
 * @return
 */
public int getLongestSuffixLength(String word)
{
  word = reverse(word);
  LinkedList<Map.Entry<String, Integer>> suffixList = trie.commonPrefixSearchWithValue(word);
  if (suffixList.size() == 0) return 0;
  return suffixList.getLast().getValue();
}
origin: org.mockito/mockito-core

public boolean isEmpty() {
  synchronized (invocations) {
    return invocations.isEmpty();
  }
}
origin: google/guava

 private void runNext() {
  tasks.removeFirst().run();
 }
}
origin: hankcs/HanLP

@Override
public boolean add(Pipe<M, M> pipe)
{
  return pipeList.add(pipe);
}
origin: org.mockito/mockito-core

public static Invocation findPreviousVerifiedInOrder(List<Invocation> invocations, InOrderContext context) {
  LinkedList<Invocation> verifiedOnly = ListUtil.filter(invocations, new RemoveUnverifiedInOrder(context));
  if (verifiedOnly.isEmpty()) {
    return null;
  } else {
    return verifiedOnly.getLast();
  }
}
origin: hankcs/HanLP

@Override
public boolean isEmpty()
{
  return pipeList.isEmpty();
}
java.utilLinkedList

Javadoc

Doubly-linked list implementation of the List and Dequeinterfaces. Implements all optional list operations, and permits all elements (including null).

All of the operations perform as could be expected for a doubly-linked list. Operations that index into the list will traverse the list from the beginning or the end, whichever is closer to the specified index.

Note that this implementation is not synchronized. If multiple threads access a linked list concurrently, and at least one of the threads modifies the list structurally, it must be synchronized externally. (A structural modification is any operation that adds or deletes one or more elements; merely setting the value of an element is not a structural modification.) This is typically accomplished by synchronizing on some object that naturally encapsulates the list. If no such object exists, the list should be "wrapped" using the Collections#synchronizedListmethod. This is best done at creation time, to prevent accidental unsynchronized access to the list:

 
List list = Collections.synchronizedList(new LinkedList(...));

The iterators returned by this class's iterator and listIterator methods are fail-fast: if the list is structurally modified at any time after the iterator is created, in any way except through the Iterator's own remove or add methods, the iterator will throw a ConcurrentModificationException. Thus, in the face of concurrent modification, the iterator fails quickly and cleanly, rather than risking arbitrary, non-deterministic behavior at an undetermined time in the future.

Note that the fail-fast behavior of an iterator cannot be guaranteed as it is, generally speaking, impossible to make any hard guarantees in the presence of unsynchronized concurrent modification. Fail-fast iterators throw ConcurrentModificationException on a best-effort basis. Therefore, it would be wrong to write a program that depended on this exception for its correctness: the fail-fast behavior of iterators should be used only to detect bugs.

This class is a member of the Java Collections Framework.

Most used methods

  • <init>
    Constructs a list containing the elements of the specified collection, in the order they are returne
  • add
    Appends the specified element to the end of this list.This method is equivalent to #addLast.
  • size
    Returns the number of elements in this list.
  • isEmpty
  • removeFirst
    Removes and returns the first element from this list.
  • addFirst
    Inserts the specified element at the beginning of this list.
  • addLast
    Appends the specified element to the end of this list.This method is equivalent to #add.
  • clear
    Removes all of the elements from this list. The list will be empty after this call returns.
  • remove
    Removes the first occurrence of the specified element from this list, if it is present. If this list
  • get
    Returns the element at the specified position in this list.
  • removeLast
    Removes and returns the last element from this list.
  • iterator
  • removeLast,
  • iterator,
  • getFirst,
  • getLast,
  • addAll,
  • toArray,
  • contains,
  • poll,
  • listIterator,
  • pop

Popular in Java

  • Finding current android device location
  • requestLocationUpdates (LocationManager)
  • scheduleAtFixedRate (Timer)
  • getSystemService (Context)
  • GridLayout (java.awt)
    The GridLayout class is a layout manager that lays out a container's components in a rectangular gri
  • ByteBuffer (java.nio)
    A buffer for bytes. A byte buffer can be created in either one of the following ways: * #allocate
  • Charset (java.nio.charset)
    A charset is a named mapping between Unicode characters and byte sequences. Every Charset can decode
  • Date (java.sql)
    A class which can consume and produce dates in SQL Date format. Dates are represented in SQL as yyyy
  • ExecutorService (java.util.concurrent)
    An Executor that provides methods to manage termination and methods that can produce a Future for tr
  • Executors (java.util.concurrent)
    Factory and utility methods for Executor, ExecutorService, ScheduledExecutorService, ThreadFactory,
  • 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