a singly linked list, output includes spaces - Java -


so, console, input this. (the app class working fine, that's not issue)

j [[1, 2, 3] [4, 5] [6, 7]] 

and output this:

[1, 2, 3, , 4, 5, , 6, 7] 

essentially, it's picking whitespaces or something. here's code:

 public static <e> sllist<e> joinallcopy(list<sllist<e>> lists) { sllist<e> result = new sllist<e>();  for(int = 1; < lists.size(); i++){      sllist <e> temp = lists.get(i);      result = lists.get(0);     node<e> curr = temp.first;     while(curr != null){     result.addlast(curr.item);     curr = curr.next;     }        }  return result; } 

what doing, taking in arraylist of singlylinked lists, , iterating through them each element, , adding them result. anyway can including whitespaces without altering given tostring method?

all work needs done inside method, nothing outside of needs altered. have been killing myself on 24 hours now, can't seem find way. d:

edit: think it's because curr.next points null value @ end of iterating list, , includes in final is. however, may not so.

thanks, lachlan

you can check while inserting item whether empty (if possible):

if(! curr.item.isempty() )     result.addlast(curr.item); 

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -