Questions tagged [collections]

Collections APIs provide developers with a set of classes and interfaces that make it easier to handle collections of objects.

collections
Filter by
Sorted by
Tagged with
10 votes
3 answers
15k views

WPF Databinding With A Collection Object

I have a simple class as defined below: public class Person { int _id; string _name; public Person() { } public int ID { get { return _id; } set { _id = value;...
Randster's user avatar
  • 298
2 votes
1 answer
2k views

WPF: how to define collections for use in xaml

I want to define something like this <myCustomControl> <myCustomControl.Images> <Image Source="{StaticResource LockedIcon16}" /> <Image Source="{...
Aran Mulholland's user avatar
1 vote
1 answer
471 views

Architecture choice about representation of collections in Business Objects

I have made certain choices in my architecture which I request the community to review and comment. I am breaking up the post in smaller sections to make it easier to understand the context and then ...
Rajarshi's user avatar
  • 174
0 votes
1 answer
83 views

How can I reduce the number of loops in this VIEW in Rails when using :collection?

I am using the :collection to go through all the Contacts that are part of a given Campaign. But within that Campaign I check for three different Models (each with their own partial). Feels like I ...
Satchel's user avatar
  • 16.6k
43 votes
8 answers
27k views

Is it better to use List or Collection?

I have an object that stores some data in a list. The implementation could change later, and I don't want to expose the internal implementation to the end user. However, the user must have the ability ...
Vivin Paliath's user avatar
1 vote
2 answers
341 views

NHibernate : Root collection with an root object

I want to track a list of root objects which are not contained by any element. I want the following pseudo code to work: using (session1 = [...]) { IList<FavoriteItem>list = session1.Linq<...
Daniel's user avatar
  • 21
5 votes
3 answers
2k views

Return number of matches from c# dictionary

I have a dictionary with non unique values and I want to count the matches of a string versus the values. Basically I now do dict.ContainsValue(a) to get a bool telling me if the string a exists in ...
Rickard Haake's user avatar
3 votes
4 answers
492 views

Object Design: How to Organize/Structure a "Collection Class"

I'm currently struggling to understand how I should organize/structure a class which I have already created. The class does the following: As its input in the constructor, it takes a collection of ...
CrimsonX's user avatar
  • 9,128
22 votes
7 answers
13k views

Why does C# not implement GetHashCode for Collections?

I am porting something from Java to C#. In Java the hashcode of a ArrayList depends on the items in it. In C# I always get the same hashcode from a List... Why is this? For some of my objects the ...
Peterdk's user avatar
  • 15.8k
1 vote
3 answers
3k views

WPF/MVVM: Delegating a domain Model collection to a ViewModel

A domain model collection (normally a List or IEnumerable) is delegated to a ViewModel. Thats means my CustomerViewModel has a order collection of type List or IEnumerable. No change in the list is ...
msfanboy's user avatar
  • 5,293
5 votes
5 answers
507 views

Quickest and most efficient method to search top 3 numbers?

I currently have an array of around 8 - 10 numbers that changes on a periodic basis. So around every 5 - 10 seconds the numbers get updated. I need to get the top 3 numbers in the array every 10 ...
Donal Rafferty's user avatar
2 votes
5 answers
709 views

"Collection was modified..." Issue

I've got a function that checks a list of objects to see if they've been clicked and fires the OnClick events accordingly. I believe the function is working correctly, however I'm having an issue: ...
Tyler Murry's user avatar
  • 2,735
3 votes
1 answer
260 views

How to change order in ordered+persisted collection?

I just need to change order of items in a (previously persisted) ordered collection... I tried simply passing the re-arranged collection to a setter: after committing a transaction the collection is ...
Jaroslav Záruba's user avatar
1 vote
1 answer
218 views

How do I select XML elements into a strongly-typed collection using LINQ?

I am trying to wrap my brain around using LINQ as a means of working with XML data and I'm having a problem figuring out the best way to select elements into a strongly-typed collection. I'm sure ...
mclark1129's user avatar
  • 7,592
2 votes
1 answer
616 views

AutoMapping Custom Collections with FluentNHibernate

I am retrofitting a very large application to use NHibernate as it's data access strategy. Everything is going well with AutoMapping. Luckily when the domain layer was built, we used a code generator. ...
ScottBelchak's user avatar
  • 1,427
8 votes
2 answers
3k views

Java multiple generic collection parameters compile error

So strange! Please have a look the code first: public class A {} public class B extends A {} public class C extends A {} public class TestMain { public <T extends A> void test(T a, T b) ...
Geln Yang's user avatar
  • 912
2 votes
7 answers
351 views

Concise C# code for gathering several properties with a non-null value into a collection?

A fairly basic problem for a change. Given a class such as this: public class X { public T A; public T B; public T C; ... // (other fields, properties, and methods are not of ...
stakx - no longer contributing's user avatar
5 votes
3 answers
4k views

Why does the Java Collections Framework offer two different ways to sort?

If I have a list of elements I would like to sort, Java offers two ways to go about this. For example, lets say I have a list of Movie objects and I’d like to sort them by title. One way I could ...
dvanaria's user avatar
  • 6,753
0 votes
1 answer
106 views

which collection should I use

I have a number of custom objects of type X. X has a number of parameters and must be unique in the collection. (I created my own equals method based on the custom parameters to examine this) In each ...
Masna's user avatar
  • 223
2 votes
1 answer
273 views

google collections ordering on map values

I would like to order a map(A,Double) based on the values. Function<Map.Entry<A, Double>, Double> getSimFunction = new Function<Map.Entry<A, Double>, Double>() { ...
user326667's user avatar
5 votes
3 answers
17k views

Compare two lists

I want to compare two lists. Since we code to interface using List, which does not inherit the equals from from the Object class. How do I do this?
javaguy's user avatar
  • 4,424
2 votes
3 answers
14k views

Iterator in Java

What is Iterator and collections? Does these two have any relations? // the interface definition Interface Iterator { boolean hasNext(); Object next(); // note "one-way" traffic void ...
Kevin's user avatar
  • 23.4k
0 votes
2 answers
100 views

Collection, which method is used to authorize an add of an element?

We find a lot of concrete subclasses under Collection. While trying to add an element in a concrete collection, this collection will use a method to determine if it can accept to store the element (...
Duke Vador's user avatar
30 votes
4 answers
53k views

UnsupportedOperationException on Collection

While studying the Collection API, we find that some methods (add, remove,...) may throw a java.lang.UnsupportedOperationException if the current implementation of the Collection does not support ...
Duke Vador's user avatar
2 votes
1 answer
900 views

How to create reference tables using fluent nhibernate

How can i create a 3 table schema from the following model classes. public class Product { public int Id {get; set;} public string Name {get; set;} public IList<Photo> Photos {get; set;} }...
user avatar
0 votes
2 answers
4k views

Java - Collections.binarySearch with PriorityQueue?

Can I use Collections.binarySearch() method to search elements in a PriorityQueue? Otherwise, how can I apply search algorithms to a PriorityQueue? I have this (class Evento implements Comparable): ...
cidadao's user avatar
  • 1,433
1 vote
3 answers
305 views

how do I best create a set of list classes to match my business objects

I'm a bit fuzzy on the best way to solve the problem of needing a list for each of my business objects that implements some overridden functions. Here's the setup: I have a baseObject that sets up ...
KenF's user avatar
  • 132
19 votes
5 answers
40k views

Java - Collections.sort() performance

I'm using Collections.sort() to sort a LinkedList whose elements implements Comparable interface, so they are sorted in a natural order. In the javadoc documentation its said this method uses ...
cidadao's user avatar
  • 1,433
-1 votes
1 answer
221 views

synchronized,immutable,empty collection

Using Collections class we can make any collection synchronized,immutable or empty what are there respective uses, when we need to implement these type of collections
subhashis's user avatar
  • 4,695
42 votes
1 answer
10k views

Vector vs Collections.synchronizedList(ArrayList)

Vector is synchronized, ArrayList is not synchronized but we can synchronize an ArrayList by Collections.synchronizedList(aList), so which will perform better and faster?
subhashis's user avatar
  • 4,695
2 votes
4 answers
3k views

C# Get Type of IEnumerable<TModel>

I have a method to which I pass an IEnumerable<TModel>. Then depending on the type of TModel, the method carries out a set of instructions as below: public void MyMethod<TModel>(...
Jimbo's user avatar
  • 22.7k
5 votes
3 answers
119 views

What is the minimum interface that has the Count property in .Net

I need to change a method that has one parameter that takes a serie of objects. I need to find the lowest Interface (in inheritance tree) that has the Count property. Until now I was using the ...
Ignacio Soler Garcia's user avatar
1 vote
4 answers
3k views

How can I create an empty collection from an anonymous collection most elegantly in C#?

If I have an anonymous type created by LINQ var ans = from r in someList where someCondition(r) select new { r.a, r.b }; What is the best way to create an empty matching collection so I can move ...
NetMage's user avatar
  • 26.7k
7 votes
3 answers
936 views

Java Generic Collection of Generic Type with Bounded Wildcard

Please help me with this: If Lion IS-A Animal and given Cage<T>: Cage<? extends Animal> c = new Cage<Lion>(); // ok, but Set<Cage<? extends Animal>> cc = new HashSet&...
ar_'s user avatar
  • 73
1 vote
5 answers
815 views

What are the benefits to using String[] over List<String>? [duplicate]

Possible Duplicates: c# array vs generic list Array versus List<T>: When to use which? I understand that there are several benefits of using List<>. However, I was wondering what ...
Jones's user avatar
  • 299
1 vote
3 answers
702 views

c# Best class to hold a list of values to look up after

I have a list of values that i need to check against a constant list to know wheter they are present or not (one by one). Im using a dictionary buy it doesnt seem logical to have the value two times (...
VSP's user avatar
  • 2,375
3 votes
3 answers
238 views

Why are AbstractQueue and AbstractList disjointed?

During my C learning days, when I had implemented a Queue, I implemented them on top of a LinkedList. So essentially I had two pointers (front and rear) for the Queue operations on top of LinkedList, ...
Vaibhav Bajpai's user avatar
35 votes
7 answers
15k views

Difference between a deprecated and a legacy API?

I was studying the legacy API's in the Java's Collection Framework and I learnt that classes such as Vector and HashTable have been superseded by ArrayList and HashMap. However still they are NOT ...
Vaibhav Bajpai's user avatar
4 votes
3 answers
2k views

What causes this retainAll exception?

java.lang.UnsupportedOperationException: This operation is not supported on Query Results at org.datanucleus.store.query.AbstractQueryResult.contains(AbstractQueryResult.java:250) at java.util....
Joren's user avatar
  • 9,743
11 votes
3 answers
43k views

How to create collection object in VBScript?

What should be the parameter for CreateObject? See this example: Dim a Set a = CreateObject("Collection") 'getting a runtime error saying ActiveX ' component can't create object: '...
Onnesh's user avatar
  • 1,189
0 votes
2 answers
18k views

document.getElementById('').length = 0 doesn't work under Win7

I have a select list: <select id="sel"> <option>text1</option> <option>text2</option> <option>text3</option> <option>text4</...
Simon's user avatar
  • 22.9k
1 vote
7 answers
3k views

for (Object object : list) [java] construction

My question, is, whether the sequence of elements picked from a list will always be the same, is this construction behaviour is deterministic for java "List"s - descendants of java.util....
EugeneP's user avatar
  • 11.9k
0 votes
1 answer
2k views

WPF How to bind to a specific element in the Collection

I want to make a binding to a specific element in the Collection. But I cannot figure out how to write the Binding. This is the code: public class MySource { .. public string SomeProp; public ...
theSpyCry's user avatar
  • 12.2k
12 votes
6 answers
33k views

magento limiting number of returned items in product collection call

Im trying to limit the number of returned results manually in a copy of the list.phtml template, but its turning out to be alot harder than I anticipated. Ive tried manually setting the collection ...
thrice801's user avatar
  • 1,671
2 votes
1 answer
255 views

Self-updating collection concurrency issues

I am trying to build a self-updating collection. Each item in the collection has a position (x,y). When the position is changed, an event is fired, and the collection will relocate the item. ...
DEHAAS's user avatar
  • 1,294
0 votes
1 answer
373 views

How to pass data from VB.NET to ActiveX.exe?

I've created a MAPI Wrapper in VB6 and compiled it as an ActiveX.exe so I can use it in my VB.NET project. The project is a windows service that takes data from a webservice passes data to activex....
Kral24's user avatar
  • 31
5 votes
4 answers
2k views

How created method with signature as List

I'm very new to Java programming language so this is probably dumb question but I have to ask it because I can't figure it out on my own. Here is the deal. I want to create method which extracts ...
London's user avatar
  • 15.1k
61 votes
15 answers
171k views

How to remove duplicates from a list?

I want to remove duplicates from a list but what I am doing is not working: List<Customer> listCustomer = new ArrayList<Customer>(); for (Customer customer: tmpListCustomer) { if (!...
Mercer's user avatar
  • 9,886
2 votes
1 answer
98 views

Is there a collection in .Net that supports sorted values only. Keys are not needed?

I am looking for something like a tree. We are constantly inserting into an already sorted collection. We would like access to the minimum and maximum value. We don't need any keys, just the value. I ...
uriDium's user avatar
  • 13.3k
4 votes
5 answers
1k views

how to selectively filter items in a collection

I use the following snippet to filter the list of selected users, where isSelected is a boolean variable. Is there a simpler way (helper function) to populate the selectedUsers collection instead of ...
Sam's user avatar
  • 8,535

1
451 452
453
454 455
483