Wednesday, 15 May 2013

java - 'popping' off an element in an arraylist. what am I missing? -


OK is a string of input numbers and operators like + 2 3 * 4. I want to split a string In ArrayList object, with each character in its string being indexed. Here I have;

  string turned on; String s = "+ 2 3 * 4"; List & lt; String & gt; Splitter = new array list & lt; String & gt; (Arrays.asList (s.split ("\\ s +"))); Current = splitter. Rev. (0); If (current == "+") {// do stuff} and if (current = "-") {// do stuff} .... if the statements aren 'not evaluated as correct for any reason Going, is there something subtle missing or am I completely wrong here?  

Thanks for the help. ==

In , you < Code> == to compare the wire; Use instead In

else , you are using the assignment operator = to compare the string; Instead use string # likeness .

== The operator compares the comparison of two string references to see if you see the same object, which is not what you want.

No comments:

Post a Comment