collections

Make ArrayList element case-insensitive

In my Java application i need to compare two list's element whether it is similar or not. In short suppose i have two list declared like shown below List<String> a = new ArrayList<String>(); a.add("one"); a.add("three"); a.add("two"); Collections.sort(a); List<String> a1 = new ArrayList<String>(); a1.add("ONE"); a...

What is the best way to save a matrix of Checkboxes when x/y are not known until runtime?

I need to keep checkboxes in a collection and access them via matrix coordinates. The following example works but only if I know the size of the matrix beforehand, since an array is used. What would be the best kind of approach/collection to achieve the same result but also allow the matrix to be defined at runtime, e.g. Dictionary<>, ...

What is the quickest generic collection?

I have the following scenario. I have two collections, one has some items missing. What collection type would be the quickest to find the missing items and insert them? ...

Fixed-size collection that keeps top (N) values

My code processes a huge number of values and I'm looking for an efficient structure to keep track of the top (N) values, where N is less than 10, so collecting ALL numbers then sorting the list and taking the first (N) is probably not the most efficient way. To do that, I'm building a collection of fixed size N, to keep the top (N) va...

Skip first row in a Matrix, and validate width/height.

I have an matrix in this format that I am trying to validate and remove first row: 3 4 0 0 0 0 0 0 0 0 0 0 0 0 Where the first line is and the other lines are the actual data. Width Height What is the best way to A remove the first row, and B validate that all rows meet the Width Height Criteria specified? I could do a simple for...

Does this NullPointerException refer to getFoos returning null or some problem with the cast from a Collection to an ArrayList?

Why does this line cause a NullPointerException: List<Foo> foos = new ArrayList<Foo>(userDetailsService.getFoos(currentUser)); The getFoos method simply returns a Collection of Foos: public Collection<Foo> getFoos(final String username) I can't tell if the NullPointerException refers to getFoos returning null or some proble...

Seq for fast random access and fast growth in Scala

What would be the best Scala collection (in 2.8+), mutable or immutable, for the following scenario: Sequentially ordered, so I can access items by position (a Seq) Need to insert items frequently, so the collection must be able to grow without too much penalty Random access, frequently need to remove and insert items at arbitrary inde...

VB.NET: Populating a list in Linq

Assume I have the following XML file: <Movies> <Movie ownerName="Ryan"> <Title>The Lord of the Rings Trilogy</Title> <Title>Saving Private Ryan</Title> <Title>etc</Title> </Movie> <Movie ownerName="Rynina"> <Title>Foo</Title> <Title>Bar</Title> </Movie> </Movies> Wh...

ArrayList.remove(int index) not working with non-anonymous class object

Hi All, ArrayList.remove(int index) is working with the anonymous instance of ActionListener class :- DeleteModule.java :- import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.ArrayList; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JOptionP...

Fluent Nhibernate - Collection name naming convention

Is it possible to set a naming convention for all collection of an entity even if I use the Access Strategy or not, so that all collection names are {EnityName}s instead of {entityName}s (because of Access.CamelCaseField(Prefix.Underscore) the first letter is lower)? Or is there a way where I can tell NHibernate that it shall use the as...

before_destroy is not firing from update_attributes

I have a student that has many courses. In the student#update action and form, I accept a list of course_ids. When that list changes, I'd like to call a certain function. The code I have does get called if the update_attributes creates a course_student, but does not get called if the update_attributes destroys a course_student. Can I get...

Best practice concerning private arraylist and other such constructions

Hello all, I have the following class which I'm fighting over how to implement. The question is whether or not it makes sense to have a private collection item, in this case an arraylist, a a member. I am well aware it is considered best practice to have getters and setters for any class members, but in this case having a getter and set...

How to invoke System.Linq.Enumerable.Count<> on IEnumerable<T> using Reflection?

I have a bunch of IEnumerable Collections which exact number and types is subject of frequent changes (due to automatic code generation). It looks something like this: public class MyCollections { public System.Collections.Generic.IEnumerable<SomeType> SomeTypeCollection; public System.Collections.Generic.IEnumerable<OtherType>...

Is there any AS collection framework that can used in ComboBox and DataGrid

I know AS3Commons-collection framework is a good one, but it can't use in ComboBox, recently I try to use LinkedSet data structure to retrieve and store data in ComboBox, any one can help me? thanks in advance. ...

Java collections: What happens when "size" exceeds "int"?

I know that Java collections are very memory-hungry, and did a test myself, proving that 4GB is barely enough to store few millions of Integers into a HashSet. But what if I has "enough" memory? What would happen to Collection.size()? EDIT: Solved: Collection.size() returns Integer.MAX when the integer range is exceeded. New question: ...

Using hamcrest for comparing each item in two separate lists with own matcher

Hello, i try to compare two lists with each other: ListA (a1,a2,a3,...) ListB (b1,b2,b3,...) I want that a1 is compared to b1, a2 to b2, a3 to b3, .... But i have to use another method and cannot use .equals! I have written my own hamcrest matcher. But i have to use a for loop to iterate over the elements. is there a better solutio...

Instantiating a generic type?

I'm currently working on a generic collection class and I'd like to create a method which returns an object from the collection. If the specific object does not exist in the collection then the object should be created, added to the collection, and then returned. I'm accounting a few problems though. The generic collection if of a typ...

Turning a collection into a datagrid

So I have a collection that I have in a listbox right now, which displays each item in the collection. I want to turn the listbox into a gridview, so I can add checkboxes and other drop downs. I am unable to find a tutorial that explains how to do this. For the example my collection has 2 items, each item has multiple columns. [0] ...

Configuration Element Collection Section

I would like to set up a custom app configuration element collection section like this ` <logSection name="Testttt"> <properties name ="Pride"> <pathName="TestingLog.txt"/> <deleteRetention="100"/> <deleteZeroRetention="5"/> <wildcard="*.txt"/> </properties> <properties name ="Adhoc"> ...

What is mean by Collection<? extends EmpApp>?

In my code i am using two different class objects empobj & employee. Eclipse asks to change the code empobj.addAll(employee); to empobj.addAll((Collection<? extends EmpApp>) employee); What does it mean? I cannot understand the concept here. Can I get any clarifications about this? ...