本文整理了Java中java.util.LinkedList.<init>()
方法的一些代码示例,展示了LinkedList.<init>()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。LinkedList.<init>()
方法的具体详情如下:
包路径:java.util.LinkedList
类名称:LinkedList
方法名:<init>
[英]Constructs an empty list.
[中]构造一个空列表。
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: spring-projects/spring-framework
@Override
public List<FieldError> getFieldErrors() {
List<FieldError> result = new LinkedList<>();
for (ObjectError objectError : this.errors) {
if (objectError instanceof FieldError) {
result.add((FieldError) objectError);
}
}
return Collections.unmodifiableList(result);
}
代码示例来源:origin: prestodb/presto
public void appendReferring(Referring currentReferring) {
if (_referringProperties == null) {
_referringProperties = new LinkedList<Referring>();
}
_referringProperties.add(currentReferring);
}
代码示例来源:origin: stackoverflow.com
// Collection of items to process in parallel
Collection<Integer> elems = new LinkedList<Integer>();
for (int i = 0; i < 40; ++i) {
elems.add(i);
}
Parallel.For(elems,
// The operation to perform with each item
new Parallel.Operation<Integer>() {
public void perform(Integer param) {
System.out.println(param);
};
});
代码示例来源:origin: google/j2objc
public static Map bucket(Collection c, Transformer t) {
Map buckets = new HashMap();
for (Iterator it = c.iterator(); it.hasNext();) {
Object value = (Object)it.next();
Object key = t.transform(value);
List bucket = (List)buckets.get(key);
if (bucket == null) {
buckets.put(key, bucket = new LinkedList());
}
bucket.add(value);
}
return buckets;
}
代码示例来源:origin: skylot/jadx
public static List<BlockNode> buildSimplePath(BlockNode block) {
List<BlockNode> list = new LinkedList<>();
BlockNode currentBlock = block;
while (currentBlock != null
&& currentBlock.getCleanSuccessors().size() < 2
&& currentBlock.getPredecessors().size() == 1) {
list.add(currentBlock);
currentBlock = getNextBlock(currentBlock);
}
if (list.isEmpty()) {
return Collections.emptyList();
}
return list;
}
代码示例来源:origin: apache/incubator-shardingsphere
private List<ShardingExecuteGroup<StatementExecuteUnit>> getSQLExecuteGroups(
final String dataSourceName, final List<SQLUnit> sqlUnits, final SQLExecutePrepareCallback callback) throws SQLException {
List<ShardingExecuteGroup<StatementExecuteUnit>> result = new LinkedList<>();
int desiredPartitionSize = Math.max(0 == sqlUnits.size() % maxConnectionsSizePerQuery ? sqlUnits.size() / maxConnectionsSizePerQuery : sqlUnits.size() / maxConnectionsSizePerQuery + 1, 1);
List<List<SQLUnit>> sqlUnitPartitions = Lists.partition(sqlUnits, desiredPartitionSize);
ConnectionMode connectionMode = maxConnectionsSizePerQuery < sqlUnits.size() ? ConnectionMode.CONNECTION_STRICTLY : ConnectionMode.MEMORY_STRICTLY;
List<Connection> connections = callback.getConnections(connectionMode, dataSourceName, sqlUnitPartitions.size());
int count = 0;
for (List<SQLUnit> each : sqlUnitPartitions) {
result.add(getSQLExecuteGroup(connectionMode, connections.get(count++), dataSourceName, each, callback));
}
return result;
}
代码示例来源:origin: stackoverflow.com
List list = new LinkedList();
List spy = spy(list);
//optionally, you can stub out some methods:
when(spy.size()).thenReturn(100);
//using the spy calls real methods
spy.add("one");
spy.add("two");
//size() method was stubbed - 100 is printed
System.out.println(spy.size());
代码示例来源:origin: spring-projects/spring-framework
/**
* Return a FlashMap contained in the given list that matches the request.
* @return a matching FlashMap or {@code null}
*/
@Nullable
private FlashMap getMatchingFlashMap(List<FlashMap> allMaps, HttpServletRequest request) {
List<FlashMap> result = new LinkedList<>();
for (FlashMap flashMap : allMaps) {
if (isFlashMapForRequest(flashMap, request)) {
result.add(flashMap);
}
}
if (!result.isEmpty()) {
Collections.sort(result);
if (logger.isTraceEnabled()) {
logger.trace("Found " + result.get(0));
}
return result.get(0);
}
return null;
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testComplexGenericMap() {
Map<List<String>, List<String>> inputMap = new HashMap<>();
List<String> inputKey = new LinkedList<>();
inputKey.add("1");
List<String> inputValue = new LinkedList<>();
inputValue.add("10");
inputMap.put(inputKey, inputValue);
ComplexMapHolder holder = new ComplexMapHolder();
BeanWrapper bw = new BeanWrapperImpl(holder);
bw.setPropertyValue("genericMap", inputMap);
assertEquals(new Integer(1), holder.getGenericMap().keySet().iterator().next().get(0));
assertEquals(new Long(10), holder.getGenericMap().values().iterator().next().get(0));
}
代码示例来源:origin: crossoverJie/JCSprout
public List<Integer> splitRedPacket(int money, int count) {
List<Integer> moneys = new LinkedList<>();
//金额检查,如果最大红包 * 个数 < 总金额;则需要调大最小红包 MAX_MONEY
if (MAX_MONEY * count <= money) {
System.err.println("请调大最小红包金额 MAX_MONEY=[" + MAX_MONEY + "]");
return moneys ;
}
//计算出最大红包
int max = (int) ((money / count) * TIMES);
max = max > MAX_MONEY ? MAX_MONEY : max;
for (int i = 0; i < count; i++) {
//随机获取红包
int redPacket = randomRedPacket(money, MIN_MONEY, max, count - i);
moneys.add(redPacket);
//总金额每次减少
money -= redPacket;
}
return moneys;
}
代码示例来源:origin: hankcs/HanLP
int length = roleTagList.size() - 1;
List<E> tagList = new LinkedList<E>();
Iterator<EnumItem<E>> iterator = roleTagList.iterator();
EnumItem<E> start = iterator.next();
E pre = start.labelMap.entrySet().iterator().next().getKey();
E perfect_tag = pre;
tagList.add(pre);
for (int i = 0; i < length; ++i)
EnumItem<E> item = iterator.next();
for (E cur : item.labelMap.keySet())
tagList.add(pre);
代码示例来源:origin: stackoverflow.com
// with two levels of indirection
List<ArrayList> alist = new ArrayList<ArrayList>();
List<List> list = (List) alist; // gives you a warning.
list.add(new LinkedList()); // adding a LinkedList into a list of ArrayList!!
System.out.println(alist.get(0)); // runtime error
代码示例来源:origin: apache/incubator-shardingsphere
private CommandResponsePackets executeForMasterSlave() throws InterruptedException, ExecutionException, TimeoutException {
String dataSourceName = new MasterSlaveRouter(((MasterSlaveSchema) logicSchema).getMasterSlaveRule(),
GLOBAL_REGISTRY.getShardingProperties().<Boolean>getValue(ShardingPropertiesConstant.SQL_SHOW)).route(sql).iterator().next();
synchronizedFuture = new SynchronizedFuture(1);
FutureRegistry.getInstance().put(connectionId, synchronizedFuture);
executeSQL(dataSourceName, sql);
List<QueryResult> queryResults = synchronizedFuture.get(
GLOBAL_REGISTRY.getShardingProperties().<Long>getValue(ShardingPropertiesConstant.PROXY_BACKEND_CONNECTION_TIMEOUT_SECONDS), TimeUnit.SECONDS);
FutureRegistry.getInstance().delete(connectionId);
List<CommandResponsePackets> packets = new LinkedList<>();
for (QueryResult each : queryResults) {
packets.add(((MySQLQueryResult) each).getCommandResponsePackets());
}
return merge(new SQLJudgeEngine(sql).judge(), packets, queryResults);
}
代码示例来源:origin: spotbugs/spotbugs
/**
* Enumerate the simple paths.
*
* @return this object
*/
public SimplePathEnumerator enumerate() {
Iterator<Edge> entryOut = cfg.outgoingEdgeIterator(cfg.getEntry());
if (!entryOut.hasNext()) {
throw new IllegalStateException();
}
Edge entryEdge = entryOut.next();
LinkedList<Edge> init = new LinkedList<>();
init.add(entryEdge);
work(init);
if (DEBUG && work == maxWork) {
System.out.println("**** Reached max work! ****");
}
return this;
}
代码示例来源: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: spring-projects/spring-framework
private void doTestMultipartHttpServletRequest(MultipartHttpServletRequest request) throws IOException {
Set<String> fileNames = new HashSet<>();
Iterator<String> fileIter = request.getFileNames();
while (fileIter.hasNext()) {
fileNames.add(fileIter.next());
}
assertEquals(2, fileNames.size());
assertTrue(fileNames.contains("file1"));
assertTrue(fileNames.contains("file2"));
MultipartFile file1 = request.getFile("file1");
MultipartFile file2 = request.getFile("file2");
Map<String, MultipartFile> fileMap = request.getFileMap();
List<String> fileMapKeys = new LinkedList<>(fileMap.keySet());
assertEquals(2, fileMapKeys.size());
assertEquals(file1, fileMap.get("file1"));
assertEquals(file2, fileMap.get("file2"));
assertEquals("file1", file1.getName());
assertEquals("", file1.getOriginalFilename());
assertNull(file1.getContentType());
assertTrue(ObjectUtils.nullSafeEquals("myContent1".getBytes(), file1.getBytes()));
assertTrue(ObjectUtils.nullSafeEquals("myContent1".getBytes(),
FileCopyUtils.copyToByteArray(file1.getInputStream())));
assertEquals("file2", file2.getName());
assertEquals("myOrigFilename", file2.getOriginalFilename());
assertEquals("text/plain", file2.getContentType());
assertTrue(ObjectUtils.nullSafeEquals("myContent2".getBytes(), file2.getBytes()));
assertTrue(ObjectUtils.nullSafeEquals("myContent2".getBytes(),
FileCopyUtils.copyToByteArray(file2.getInputStream())));
}
代码示例来源:origin: stanfordnlp/CoreNLP
public List<T> asSortedList() {
LinkedList<T> list = new LinkedList<>();
for (Iterator<T> i = elements.iterator(); i.hasNext();) {
list.addFirst(i.next());
}
return list;
}
代码示例来源:origin: osmandapp/Osmand
public void removeDownloaderCallback(IMapDownloaderCallback callback) {
LinkedList<WeakReference<IMapDownloaderCallback>> ncall = new LinkedList<WeakReference<IMapDownloaderCallback>>(callbacks);
Iterator<WeakReference<IMapDownloaderCallback>> it = ncall.iterator();
while (it.hasNext()) {
IMapDownloaderCallback c = it.next().get();
if (c == callback) {
it.remove();
}
}
callbacks = ncall;
}
代码示例来源:origin: apache/incubator-shardingsphere
private <I, O> List<O> serialExecute(final Collection<ShardingExecuteGroup<I>> inputGroups, final ShardingGroupExecuteCallback<I, O> firstCallback,
final ShardingGroupExecuteCallback<I, O> callback) throws SQLException {
List<O> result = new LinkedList<>();
Iterator<ShardingExecuteGroup<I>> inputGroupsIterator = inputGroups.iterator();
ShardingExecuteGroup<I> firstInputs = inputGroupsIterator.next();
result.addAll(syncGroupExecute(firstInputs, null == firstCallback ? callback : firstCallback));
for (ShardingExecuteGroup<I> each : Lists.newArrayList(inputGroupsIterator)) {
result.addAll(syncGroupExecute(each, callback));
}
return result;
}
内容来源于网络,如有侵权,请联系作者删除!