本文整理了Java中java.util.LinkedList.add()
方法的一些代码示例,展示了LinkedList.add()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。LinkedList.add()
方法的具体详情如下:
包路径:java.util.LinkedList
类名称:LinkedList
方法名:add
[英]Inserts the specified element at the specified position in this list. Shifts the element currently at that position (if any) and any subsequent elements to the right (adds one to their indices).
[中]在此列表中的指定位置插入指定元素。将当前位于该位置的元素(如果有)和任何后续元素向右移动(将一个元素添加到其索引中)。
代码示例来源:origin: prestodb/presto
public void appendReferring(Referring currentReferring) {
if (_referringProperties == null) {
_referringProperties = new LinkedList<Referring>();
}
_referringProperties.add(currentReferring);
}
代码示例来源:origin: redisson/redisson
private static void addClass(LinkedList list, CtClass c) {
Iterator it = list.iterator();
while (it.hasNext())
if (it.next() == c)
return;
list.add(c);
}
代码示例来源:origin: naman14/Timber
public void setAndRecordPlayPos(int nextPos) {
synchronized (this) {
if (mShuffleMode != SHUFFLE_NONE) {
mHistory.add(mPlayPos);
if (mHistory.size() > MAX_HISTORY_SIZE) {
mHistory.remove(0);
}
}
mPlayPos = nextPos;
}
}
代码示例来源:origin: ankidroid/Anki-Android
/**
* Sorts a card into the lrn queue LIBANKI: not in libanki
*/
private void _sortIntoLrn(long due, long id) {
Iterator i = mLrnQueue.listIterator();
int idx = 0;
while (i.hasNext()) {
if (((long[]) i.next())[0] > due) {
break;
} else {
idx++;
}
}
mLrnQueue.add(idx, new long[] { due, id });
}
代码示例来源:origin: spotbugs/spotbugs
public static void main(String args[]) {
HashSet<Integer> s = new HashSet<Integer>();
s.add(1);
s.add(2);
LinkedList<Integer> iList = new LinkedList<Integer>();
iList.add(1);
iList.add(2);
LinkedList<String> sList = new LinkedList<String>();
sList.add("x");
sList.add("y");
System.out.println(test1(s, iList));
System.out.println(test2(s, iList));
System.out.println(test3(s, sList));
System.out.println(test4(s, sList));
}
代码示例来源:origin: googleapis/google-cloud-java
@Override
protected String computeNext() {
while (true) {
if (!buffer.isEmpty()) {
return buffer.pop();
}
if (!iterator.hasNext()) {
endOfData();
return null;
}
for (Value value : iterator.next().getValuesList()) {
buffer.add(value.getStringValue());
}
}
}
};
代码示例来源:origin: stackoverflow.com
import java.util.LinkedList;
class Test {
public static void main(String args[]) {
char arr[] = {3,1,4,1,5,9,2,6,5,3,5,8,9};
LinkedList<Integer> fifo = new LinkedList<Integer>();
for (int i = 0; i < arr.length; i++)
fifo.add (new Integer (arr[i]));
System.out.print (fifo.removeFirst() + ".");
while (! fifo.isEmpty())
System.out.print (fifo.removeFirst());
System.out.println();
}
}
代码示例来源:origin: apache/kylin
private void buildIndex() {
LinkedList<TreeNode> queue = new LinkedList<>();
queue.add(root);
while (!queue.isEmpty()) {
TreeNode node = queue.removeFirst();
index.put(node.cuboidId, node);
for (TreeNode child : node.children) {
queue.add(child);
}
}
}
代码示例来源:origin: aws/aws-sdk-java
public List<StringListMap<T>> subMaps(final int size, boolean perMap) {
final LinkedList<StringListMap<T>> maps = new LinkedList<StringListMap<T>>();
int index = 0, count = 0;
for (final Entry<String,List<T>> entry : entrySet()) {
for (final T value : entry.getValue()) {
if (index == maps.size()) {
maps.add(new StringListMap<T>());
}
maps.get(index).add(entry.getKey(), value);
index = perMap ? (++count / size) : (++index % size);
}
}
return maps;
}
}
代码示例来源:origin: commons-collections/commons-collections
public static void compareSpeed() {
NodeCachingLinkedList ncll = new NodeCachingLinkedList();
LinkedList ll = new LinkedList();
System.out.println("Testing relative execution time of commonly-used methods...");
ll.removeFirst();
ll.removeLast();
ll.add(o1);
ll.remove(0);
ll.removeFirst();
ll.removeLast();
ll.add(o1);
ll.remove(0);
ll.removeFirst();
ll.removeLast();
ll.add(o1);
ll.remove(0);
System.out.println("Time with LinkedList: " + (endTime - startTime) + " ms");
System.out.println("Time with NodeCachingLinkedList: " + (endTime - startTime) + " ms");
代码示例来源:origin: osmandapp/Osmand
public static void main(String[] args) throws IOException {
OsmandRegions or = new OsmandRegions();
or.prepareFile("/Users/victorshcherb/osmand/repos/resources/countries-info/regions.ocbf");
LinkedList<WorldRegion> lst = new LinkedList<WorldRegion>();
lst.add(or.getWorldRegion());
// int i =0;
while (!lst.isEmpty()) {
WorldRegion wd = lst.pollFirst();
System.out.println((wd.superregion == null ? "" : wd.superregion.getLocaleName()) + " "
+ wd.getLocaleName() + " " + wd.getRegionDownloadName());
// if(i++ <=5)
// lst.addAll(wd.getSubregions());
}
or.cacheAllCountries();
// long t = System.currentTimeMillis();
// or.cacheAllCountries();
// System.out.println("Init " + (System.currentTimeMillis() - t));
//testCountry(or, 15.8, 23.09, "chad");
testCountry(or, 52.10, 4.92, "the netherlands", "utrecht");
testCountry(or, 52.15, 7.50, "north rhine-westphalia");
testCountry(or, 28.8056, 29.9858, "egypt");
// testCountry(or, 40.0760, 9.2807, "italy", "sardinia");
testCountry(or, 35.7521, 139.7887, "japan");
testCountry(or, 46.5145, 102.2580, "mongolia");
testCountry(or, 62.54, 43.36, "arkhangelsk oblast", "northwestern federal district");
}
代码示例来源:origin: spring-projects/spring-framework
LinkedList<String> pathElements = new LinkedList<>();
int tops = 0;
pathElements.add(0, element);
pathElements.add(0, TOP_PATH);
if (pathElements.size() == 1 && "".equals(pathElements.getLast()) && !prefix.endsWith(FOLDER_SEPARATOR)) {
pathElements.add(0, CURRENT_PATH);
代码示例来源:origin: apache/ignite
@Nullable @Override public Object call() throws Exception {
String thNm = Thread.currentThread().getName();
LinkedList<Integer> keys = new LinkedList<>();
LinkedList<Integer> old = res.put(thNm, keys);
assert old == null;
while (true) {
Integer key = keyGen.getAndIncrement();
if (key >= keyCnt)
break;
map.put(key, "value");
keys.add(key);
if (keys.size() > rememberCnt)
keys.removeFirst();
}
return null;
}
},
代码示例来源:origin: quartz-scheduler/quartz
private String[] split(String str, String splitStr) // Same as String.split(.) in JDK 1.4
{
LinkedList<String> l = new LinkedList<String>();
StringTokenizer strTok = new StringTokenizer(str, splitStr);
while(strTok.hasMoreTokens()) {
String tok = strTok.nextToken();
l.add(tok);
}
return (String[])l.toArray(new String[l.size()]);
}
代码示例来源:origin: stanfordnlp/CoreNLP
LinkedList<Tree> newChildren = new LinkedList<>();
while (!preTerms.isEmpty() && isPunc(preTerms.getFirst())) {
newChildren.add(preTerms.getFirst());
preTerms.removeFirst();
LinkedList<Tree> temp = new LinkedList<>();
if (newChild.children().length > 0) {
newChildren.add(newChild);
while (!preTerms.isEmpty() && isPunc(preTerms.getLast())) {
temp.addFirst(preTerms.getLast());
preTerms.removeLast();
while (!newChildren.isEmpty() && isPunc(newChildren.getFirst())) {
newChildren.removeFirst();
while (!newChildren.isEmpty() && isPunc(newChildren.getLast())) {
代码示例来源:origin: Activiti/Activiti
protected void flattenTree() {
flattenedList = new LinkedList<ExecutionTreeNode>();
LinkedList<ExecutionTreeNode> nodesToHandle = new LinkedList<ExecutionTreeNode>();
nodesToHandle.add(rootNode);
while (!nodesToHandle.isEmpty()) {
ExecutionTreeNode currentNode = nodesToHandle.pop();
if (reverseOrder) {
flattenedList.addFirst(currentNode);
} else {
flattenedList.add(currentNode);
}
if (currentNode.getChildren() != null && currentNode.getChildren().size() > 0) {
for (ExecutionTreeNode childNode : currentNode.getChildren()) {
nodesToHandle.add(childNode);
}
}
}
flattenedListIterator = flattenedList.iterator();
}
代码示例来源:origin: apache/rocketmq
public void samplingInMinutes() {
synchronized (this.csListHour) {
this.csListHour.add(new CallSnapshot(System.currentTimeMillis(), this.times.get(), this.value
.get()));
if (this.csListHour.size() > 7) {
this.csListHour.removeFirst();
}
}
}
代码示例来源:origin: org.codehaus.groovy/groovy
private void use(Class categoryClass) {
CachedClass cachedClass = ReflectionCache.getCachedClass(categoryClass);
LinkedList<CachedClass> classStack = new LinkedList<CachedClass>();
for (CachedClass superClass = cachedClass; superClass.getTheClass()!=Object.class; superClass = superClass.getCachedSuperClass()) {
classStack.add(superClass);
}
while (!classStack.isEmpty()) {
CachedClass klazz = classStack.removeLast();
applyUse(klazz);
}
}
代码示例来源:origin: nutzam/nutz
/**
* 访问头部开始第几个字节, 不删除
* @param index
* @return 头部的第N个字符
* @throws IOException
*/
public int peek(int index) throws IOException{
while(cache.size() <= index){
cache.add(is.read());
}
return cache.get(index);
}
代码示例来源:origin: ethereum/ethereumj
private synchronized boolean onTransactions(List<Transaction> txs) {
if (txs.isEmpty()) return false;
long[] gasPrices = new long[txs.size()];
for (int i = 0; i < txs.size(); ++i) {
gasPrices[i] = ByteUtil.byteArrayToLong(txs.get(i).getGasPrice());
}
blockGasPrices.add(gasPrices);
while (blockGasPrices.size() > getMinBlocks() &&
(calcGasPricesSize() - blockGasPrices.getFirst().length) >= getMinTransactions()) {
blockGasPrices.removeFirst();
}
return true;
}
内容来源于网络,如有侵权,请联系作者删除!