Why does java.util.ArrayList allow to add null?
I wonder why java.util.ArrayList
allows to add null
. Is there any case where I would want to add null
to an ArrayList
?
Functional Methods on Collections
I’m learning Scala and am a little bewildered by all the methods (higher-order functions) available on the collections. Which ones produce more results than the original collection, which ones produce less, and which are most appropriate for a given problem? Though I’m studying Scala, I think this would pertain to most modern functional languages (Clojure, Haskell) and also to Java 8 which introduces these methods on Java collections.
Thoughts on a custom data structure for a node/chain implementation
I am designing a simple GUI that will allow a user to create a GPX route by clicking repeatedly on a map panel. I am faced with a design dilemma for how to represent the nodes and route. This construct can be abstracted as follows:
What is the difference of the add and offer methods of Java’s PriorityQueue?
In java.util.PriorityQueue we have the methods add(E e)
and offer(E e)
. Both methods are documented as:
Is it OK to partially change a collection with PUT or DELETE?
I have a collection of products in a product group e.g.:
Fast lookup hash map implementations
I’m in the process of implementing a programming language on top of LLVM. For my polymorphic system, I’m looking for suggestions for a ultra-fast dictionary. I am not concerned with insert time, as these maps are only written to a dozen times or so. But I’m looking for super fast lookup.
I’d like to write an “ultimate shuffle” algorithm to sort my mp3 collection
I’m looking for pseudocode suggestions for sorting my mp3 files in a way that avoids title and artist repetition. I listen to crooners – Frank Sinatra, Tony Bennett, Ella Fitzgerald etc. singing old standards. Each artist records many of the same songs – Fly Me To The Moon, The Way You Look Tonight, Stardust etc. My goal is to arrange the songs (or order the playlist) with the maximum space between artists and song titles. So if I have 2000 songs and 20 are by Ella I’d like to hear her only once in every 100 songs. If 10 artists sing Fly Me To The Moon I’d like to hear it once in every 200 songs. Of course I want to combine these two requirements to create my “ultimate shuffle”.
How to unit test method that returns a collection while avoiding logic in the test
I am test-driving a method that is to generate a collection of data objects. I want to verify that the properties of the objects are being set correctly. Some of the properties will be set to the same thing; others will be set to a value which is dependent on their position in the collection. The natural way to do this seems to be with a loop. However, Roy Osherove strongly recommends against using logic in unit tests (Art of Unit Testing, 178). He says:
What is the rule on passing around collections? List vs. Ienumerable vs. IQueryable
I do Entity Framework stuff using repository patterns that are passed to the controller to than be called by the client using jquery AJAX.. Is there any basic rules on in what format I should be passing around these lists? Within the server code I suppose I could just pass around an Iqueryable? yes? And to the client I could pass around a list version ? That is my first guess..
Keeping track of all objects of a class
I’m new to object-oriented programming, and I keep running into this issue. (I’m programming in Java) I’ve been a bit reluctant to ask about this, since it seems like such a basic issue, but I can’t find any information on it, or questions about it here, and none of the textbooks I have read (on a quite basic level of course) have touched on this issue: