string - queue.remove() in Java not working -


I'm having trouble removing any element from the queue. Through extensive debugging I found that all the elements are being added, But when I try to remove one, it gives me the same element. Here's the code:

  Private synchronized string access mike (four [] myInput) {String myOutput = ""; MyOutput = convertToString (myQueue.remove ()); System.out.println ("remove accesscake:" + myOutput); } // And so you can see what is happening in the converttoastring ... private string convertertoastring (four [] a) {string migration = new string (a); Return myString.trim (); }  

If myQueue is an example of a standard Java The chance to implement the class in the Q interface, on which you got a bug with it ... ok, enough to zero is enough that we can miss it as a possibility.

If, on the other hand, you have applied your self queue, yes, maybe there may be a problem, but because mental debugging is not yet a well-established area of ​​effort, So you are going to show us the code for this: -)

I am one of two possibilities. First of all, you are somehow setting each node of your queue at the same value and you can well remove items (you can add an item to it and try to delete it) like it There is far more possibility in one language, where you can unknowingly reuse the same pointer, but there is very little possibility in Java with its improved string.

The second and most likely is that when you call not when you call then extract the element from the queue, whatever you do Even strings are returning without adjusting their underlying data structure (or, alternatively, incorrectly adjust it).

Small to see the code, it's as good as I can.


After your update that you were actually using linkeded list , I thought this is a very simple example xx.java :

  import java.util.LinkedList; Import java.util.Queue; Public square xx {public static zero main (string array []) {line  

This output:

  2 abc 1 def 0 java.util.NoSuchElementException at java.util.LinkedList.remove (LinkedList.java: 805) at java.util.LinkedList.removeFirst (Linkedist.Java 151) at java.util.LinkedList.remove (Linkedist.Javaava 98) on xx.main (xx.java14)  

As expected.

So, the bottom line is, I think we will need to see more of your code. It is difficult to think that, if a bug in was in the LinkedList or queue interface, it is not found by millions of other users yet K: -)

You also want to try by entering System.out.println (myQueue.size ()); Look at the line at some strategic places in your code that what is happening with the queue can indicate to you what is happening.


Comments

Popular posts from this blog

Eclipse CDT variable colors in editor -

AJAX doesn't send POST query -

wpf - Custom Message Box Advice -