It comes in handy of course that you can dynamically adjust the size of a List or Dictionary. But this time I want to use a Dictionary with sizes from 1 to 8. When I have e.g. size 3, it will stay that way. On the net I found a solution to use a wrapper class around a Dictionary, which could do the job. Should I resort to an array instead, or are there still other options?

Member Avatar
Member Avatar
+0 forum 4

If I have an array and an array list: int[] myArray = new int[2]; myArray[0] = 1; myArray[1] = 2; ArrayList myArrayList = new ArrayList(); myArrayList.Add("1st element"); myArrayList.AddRange(myArray); By calling the Addrange() method in myArrayList, does this add the contents of myArray to the second element of myArrayList? If so how do you access the second element of myArray through myArrayList?

Member Avatar
Member Avatar
+0 forum 4

Hi Team, Im reading Collections. It is mentioned that while intialising priority queue, it uses natural ordering by default. But my output is not like that. Below is my code and output. public class BackedCollections { public static void main(String[] args) { PriorityQueue<Integer> pq = new PriorityQueue<Integer>(); pq.offer(3); pq.offer(1); pq.offer(5); pq.offer(2); pq.offer(12); pq.offer(14); pq.offer(0); System.out.println(pq); } } ** OUTPUT ** [0, 2, 1, 3, 12, 14, 5] It Should be [0,1,2,3,5,12,15] right ? Please clarify

Member Avatar
Member Avatar
+0 forum 4

Working with polymorphism collections, list, arraylists etc. I have a sorted collection that I would like to split based on one of the objects properties. All records > 0 to one; all less than to another. I'm trying to think of the best way to implement this. I'm thinking Comparable/Comparator sorting and then iterating through the collection until I hit 0 and splitting there but it also occurs to me that theres gotta be an easier way.

Member Avatar
Member Avatar
+0 forum 5

import java.util.*; class SampleA { } class SampleB extends SampleA{ } class SampleC extends SampleA{ } class VectorDemo { public static void main(String r[]) { Vector<SampleA> v = new Vector<SampleA>(); v.add(new SampleB()); v.add(new SampleC()); SampleC rect = v.get(2); } } The output says "Incompatible types. Found SampleA, required SampleC. SampleC rect = v.get(2);" My doubt is first of all isn't this like using Wildcard where instead of saying Vector<? extends SampleA> v, we mentioned it a form of Vector<Type> v, which is one of the rules of Wild card which says if only <Type> is mentioned then it can accept …

Member Avatar
Member Avatar
+0 forum 3

iam building a training set for spam filtering using java,training set data is given as words in text files in one folder,but im unable to debug whats going wrong in java collections [CODE]/* *folder part 1 conatins various text files having name format * **spmsg***.txt and ***legit***.txt e.g 11927legit569.txt ,106127spmsgc26 * inside it it has contents like Subject: 5581 2005 47 * 1791 80 15184 64 2155 5581 2005 80 21292 10607 47 64 * 209 22910 132 1672 84 3865 84 1570 84 2005 84 10492 1847 12330 4797 82 13886 2170 47 */ package naive_bayes; import java.util.*; import …

Member Avatar
Member Avatar
+0 forum 5

EDIT: Deleted the original question. After reading, I realised that I would have to paste so much additional code that it would take someone a couple of days just to understand what was happening in my own code that it may detract from the issue at hand. Problem: When I add an object to a collection (many-to-many relationship) the object is saved and committed to the database. However, if I then try and retrieve that object somewhere else (on a different thread) the object state is incorrect and the collection does not contain the recently added item. Checking the database …

Member Avatar
Member Avatar
+1 forum 1

I know that technically, an Interface is used for reading and not writting or editing however, I want to add an add and addrange function to the following class, here is what I currently have which is not working [code] public class HrefCollection : IEnumerable<Href> { private IEnumerable<Href> hrefs; public IEnumerable<Href> Add( Href href ) { yield return href; } public IEnumerable<Href> AddRange( List<Href> hrefs ) { foreach( Href href in hrefs ) { yield return href; } } public IEnumerator<Href> GetEnumerator() { return hrefs.GetEnumerator(); } System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { return hrefs.GetEnumerator(); } } [/code] I'm not quite sure how to …

Member Avatar
Member Avatar
+1 forum 4

Hi, Although I have done a reasonable amount of coding I have very little training (self taught) so apologies if this is a stupid question. I have written a basic Defect Management app which allows developers to create a release and assign defects to it. The release object has the usual id, name etc and an object called DefectCollection with is a collection of Defect objects. When I load a Release (using it's load method) it calls the PopulateFromRelease method of the DefectCollection. This all works. However, I now have a ReleaseCollection object which I can populate from a method …

Member Avatar
Member Avatar
+0 forum 3

Hi all, and thanks for your help, in advance. I 'm stiing here with 2 choices, and I need help deciding which one to take. I want to take certain factors into account(i.e. efficiency, speed) I have values that I want to place into a SortedMap. I can do this in one of two ways: Every record I want insert has an account number. These are not unique, as one account can have more than one item on its name, i.e. an account number can appear more than once. I have a choice of two ways to put them into …

Member Avatar
+0 forum 0

The End.