Note that there are some explanatory texts on larger screens.

plurals
  1. POSimple string.equals() if statement not working Java
    primarykey
    data
    text
    <p>I'm about to go crazy. Maybe it's cause I've been working for 12 hours....but why will my if statment not evaluate to true when running <code>if (band.equals("4384")</code>?? I am printing <code>band</code> to the screen and it is reading <code>4384</code> but it will not evaluate to true. I've used .equals() so many times with out issue, what am I doing wrong?</p> <pre><code>public class Test { public static void main(String[] args) { // TODO Auto-generated method stub String endBand = " "; String str = "SCELL: UARFCN 4384, Prim. SC: 362, RSCP: 70, EcNo: 44"; endBand = getBandNumber(str); System.out.println("endBand is " + endBand); } // ************************************************ // Returns the current band that the device is on. // Currently only coded for 3G // ************************************************ private static String getBandNumber(String str) { // The string returned to str will be in the form of: // "SCELL: UARFCN 4384, Prim. SC: 362, RSCP: 73, EcNo: 33" // ^^^^ // String str = read_AT("AT+XL1SET=\"IRATSCEL?\"", 10); String band = " "; int begin = 0, end = 0; // Filter through the string to extrace the channel number for (int i = 0; i &lt; str.length(); i++) { char c = str.charAt(i); if (c == 'N' &amp;&amp; str.charAt(i + 1) == ' ') { begin = i + 1; } else if (c == ',') { end = i; break; } } band = str.substring(begin, end); System.out.println("band is " + band); if (band.equals("4384")) { band = "5"; } else { band = "2"; } return band; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload