Hey Everyone, I have this strange LinkedList problem, not sure if the problem is within the list itself, or maybe the code, as I'm not very familiar with data structures yet. Before I get started, I understand that some of you might be wondering why I need to make all these data converting, from
String to byte[] array, then from byte array to char, and eventually call Character.toString(). Well I will be sending some data over the network to
servlet, the servlet will have to process this data and return to client. The data is stored in byte array, then I cycle through the array, convert every element into char (since you can cast byte to char), add every element into LinkedList, and extract what I need as a String by calling Character.toString(). Eventually what I need is, a few Strings send from the client. I understand, that there might be some better alternatives to this (and I'm sure there is), but still, why my code below doesn't work?.
What I'm trying to do here, is encode String parameter "name" into byte array, then cycle through the array and as I said earlier convert every element into char, then add these elements into the List. Then iterate over the list, and extract values that I need, by calling Character.toString(). So the output, is always the last character in the message, if type "abcdefgh" the output will be "h", if I type "Spain", the output is "n". So why is that?
I suspect that every node in my list just points to characters of the whole String. Even if it is that, why only "h" and not "a" ? (in case of "abcdefgh").