collections Questions
11
Solved
I have an ordered LinkedHashMap and i want to add element at specific index , say at first place or last place in the map.
How can i add element in LinkedHashMap at an specific position?
Even if I...
Diarthrosis asked 6/10, 2011 at 20:1
25
Solved
I have a basic question on Java ArrayList.
When ArrayList is declared and initialized using the default constructor, memory space for 10 elements is created. Now, when I add an 11th element, what h...
Gerick asked 15/12, 2010 at 13:53
6
Solved
How can I split odd and even numbers and sum both in a collection using stream methods of Java 8?
public class SplitAndSumOddEven {
public static void main(String[] args) {
// Read the input
t...
Cleancut asked 22/1, 2016 at 5:10
4
Solved
Since Mongoid.master.collection() returns a collection even if the collection doesn't exist, we can use
coll = Mongoid.master.collection('analyticsCachedResult')
if coll.count == 0
# [...]
end
...
Caddoan asked 23/9, 2010 at 21:58
11
Solved
HashSet is based on HashMap.
If we look at HashSet<E> implementation, everything is been managed under HashMap<E,Object>.
<E> is used as a key of HashMap.
And we know that Hash...
Bainbridge asked 9/8, 2011 at 7:14
6
Solved
I have a list of "Issue" objects and i want to sort them by the "Priority" field.
The issue is that "Priority" is a string name like "HIGH", "MEDIUM" so i don't have an Id that i can sort by. How...
Empire asked 30/8, 2012 at 14:51
10
Solved
I have 60k items that need to be checked against a 20k lookup list. Is there a collection object (like List, HashTable) that provides an exceptionly fast Contains() method? Or will I have to write ...
Literality asked 17/6, 2009 at 19:37
12
Solved
I'm looking for a way to test if some given List is an unmodifiable one.
I have an object that has a List<NoMatter>, in order to offer methods such as addNoMatter(NoMatter nm) instead of all...
Tantra asked 3/12, 2011 at 1:47
4
Solved
I need an immutable list where I can get derive a second immutable list preserving all elements of the previous list plus an additional element in Java (without additional libraries).
Note: This q...
Charters asked 21/7, 2021 at 21:53
8
Solved
Don't know whether I'm having a "thick day" - but I just wondered what is the best route here.
Context:
I have a list of fields and I want to store alias names with them (I'm using .NET 2...
Coquetry asked 17/8, 2011 at 15:55
6
Solved
Is there an collection in .net that allows the storing KeyValuePair<string, string> that keeps the order of inserting?
OrderedDictionary looked promising, but seems to be rather lacking.
Now ...
Sheelah asked 18/6, 2010 at 14:52
3
Solved
I want to find the number of common elements between two lists without eliminating duplicates.
For example:
input: [1, 3, 3] & [4, 3, 3]
output: 2, since the common elements are [3, 3]
...
Mairamaire asked 8/12, 2018 at 22:18
22
Solved
I wrote myself a utility to break a list into batches of given size. I just wanted to know if there is already any apache commons util for this.
public static <T> List<List<T>> g...
Unideaed asked 19/8, 2012 at 13:34
2
When Java 21 introduced sequenced collections, I was really excited to start using them. But then I quickly found that there are various corners of the JDK where it seems like the new sequenced int...
Xanthochroism asked 19/1, 2024 at 17:58
2
Solved
Is there a data structure similar to ConcurrentDictionary<TKey,TValue> and Interlocked.Exchange<T>(...) that would allow you atomically to set a new value and retrieve the old value ass...
Yezd asked 17/1, 2024 at 22:16
6
Solved
Consider the following Code :
import java.util.*;
class Employee {
String name;
public Employee(String nm) {
this.name=nm;
}
}
public class HashMapKeyNullValue {
Employee e1;
public...
Ancestor asked 19/9, 2014 at 11:19
2
Solved
Is there a terse es6 functional way to group items by type in that it's immutable?
accounts.json
[
{"account": {"name": "Bob's credit", "type": "credit", "id": "1"}},
{"account": {"name": "sav...
Contemptible asked 30/3, 2018 at 13:28
4
Solved
contains like functionality for play.api.libs.json.Json
val data=Map("id" -> "240190", "password" -> "password","email" -> "[email protected]")
data.contains("email")//true
val in...
Emeldaemelen asked 23/7, 2014 at 7:35
22
Solved
What is the simplest way to find if two Lists contain exactly the same elements, in the standard Java libraries?
It shouldn't matter if the two Lists are the same instance or not, and it shouldn'...
Engine asked 2/7, 2009 at 17:23
10
Solved
Suppose I have a method that returns a read-only view into a member list:
class Team {
private List<Player> players = new ArrayList<>();
// ...
public List<Player> getPlayers...
Eberhardt asked 10/7, 2014 at 12:42
35
Solved
In Java 8 how can I filter a collection using the Stream API by checking the distinctness of a property of each object?
For example I have a list of Person object and I want to remove people with ...
Amaris asked 16/5, 2014 at 15:40
2
Solved
I've seen other Python programmers use defaultdict from the collections module for the following use case:
from collections import defaultdict
s = [('yellow', 1), ('blue', 2), ('yellow', 3), ('bl...
Brisson asked 23/9, 2012 at 20:25
8
Solved
By looking at the code of Collections class, i got to know that when we are using the method unmodifiableList(List list) or unmodifiableCollection(Collection c) it is not creating a new object but ...
Bod asked 6/9, 2010 at 10:24
3
Solved
If we have a Type[], we can only store Type or its subtypes in it. The same goes for ArrayList. So why is it said that one is homogeneous while the other is not?
Microtome asked 18/4, 2016 at 17:24
10
Solved
I have a collection, and I want to get the last element of it. What's the most straighforward and fast way to do so?
One solution is to first toArray(), and then return the last element of the arra...
Reams asked 2/12, 2011 at 18:18
© 2022 - 2025 — McMap. All rights reserved.