Results 1 to 7 of 7
Thread: hashmaps
- 05-02-2011, 12:46 PM #1
hashmaps
Hello im making a program that processes lists .. but im having problems with hashmaps. Im gonna show u my problem in this method .. please read the comments to understand it =)
Firstly :
Ways = Arraylist
waynodes = int array
hashnode = hashmap containing node objects .. these objects contains the ArrayList grannNodes.
My problem is when i check the objects inside of hashnode it has added to all objects the same nodes ... so when in the objects it should be size 1 (becasue 0 only has neighbour 1) its size is 169... Sorry for my english i know its crap =P.. anyway .. Hope you guys can help me figure out whats wrong =) thanksJava Code:private void getNeighbours(){ // going trough all of the ways.. for (int way = 0 ;way < Ways.size();way++){ // goign though all of the nodes for (int nod =0; nod < Ways.get(way).waynodes.length;nod++){ // if a node is the first one in the way... if ( nod == 0 ) { // at the hashnode where the name is the same as in the list i want to ad the next node only hashnode.get(Ways.get(way).waynodes[nod]).grannNodes.add(Ways.get(way).waynodes[nod + 1]); } } } }
-
the problem is, you looped through the whole list and added all of them
when you find the node you want, you should break the loop and add only that one.
Java Code:Object o = null; OuterLoop: for ( : ; ) { for ( : ; ) { boolean foundIt = something==true; if (foundIt) { //get object; o = theObject; //stop looping break OuterLoop; } } }
- 05-03-2011, 05:23 AM #3
I dont think this is my problem ... but thanks for reply ..
What i want to do is :
so im in the first stage 0 where i just have one neighbor ... 1 .. I try to take him and only add him to the current 0 object but every time i get a 0 object it adds it to ALL objects in all lists =SJava Code://loop trough all of the list for list a::: // loop trough all of the objects for all objects in list a ::: take the object before this object and the object after this object and put them in a ArrayList in this object ...
-
don't try to do it all in one line though.
Java Code://make a list List<object> currentList = new ArrayList<object>(); //add required objects to list currentList.add(get the previous object); currentList.add(get the next object); //copy the list into the current object currentObject.setList(currentList);
- 05-03-2011, 03:02 PM #5
thanks man ... I'll try that ...=P have some homework to do first =) thanks
- 05-03-2011, 03:24 PM #6
well ... its like ... I'v already added everything to the lists ... i just whant to get the neighbors =P
- 05-03-2011, 11:07 PM #7
Similar Threads
-
how can I compare HashMaps with different keys ?
By aneuryzma in forum New To JavaReplies: 6Last Post: 04-05-2011, 03:12 PM -
Concerning HashMaps
By hjensen in forum New To JavaReplies: 7Last Post: 10-18-2010, 03:36 PM -
Problems with HashMaps
By li_bi in forum New To JavaReplies: 13Last Post: 02-24-2010, 12:08 PM -
HashMaps get key for a specific value
By andre1011 in forum Advanced JavaReplies: 2Last Post: 03-11-2009, 02:30 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks