-1

I want to test if these two Strings are the same but I am not sure where I am doing wrong. Could it be because of HashMap ? how can I make this "if" work? Because of the reputation thing I cannot add any image of it![Debug mode shows val[0] -->> "000" (**id=52)****

private static String convert (final String s) {
    String temp = s;        
    final Iterator<String[]> sic = sections.iterator();
    while (sic.hasNext()) {
        final String[] val = sic.next();
        String a=val[0]; String b="000"; //val[0] is 000 and showed as "000" in debug mode as well.
        if(a.equals(b)){  //this must give a true
         val[0]="1003" ;} 

        temp = temp.replaceAll("\n(" + val[1] + ")\r?\n--*\r?\n",  val[0].length()>0 ? "\n\u25b4\u25ba"+val[0]+"\n$1\n": "\n\n\n"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
    }

    return (temp + "\u25b4").replaceAll("\u25ba212(\n" + ratioRam +"\u25b4)","\u25ba222$1"); 
}

EDIT: I thought sections are not so important here since we know the value of this section. If Sections are important then Adding synonym words different code numbers - java . Also in debug modus for a there are hash , hash32, value and in value for [0]--> 0, for [1]--> 0, for [2]---> 0

Community
  • 1
  • 1
tolgazinho
  • 13
  • 5
  • 1
    they are not exactly `equal`, what I assume there must be some space which you dont consider – Subhrajyoti Majumder May 02 '14 at 06:32
  • 2
    btw, how do you know the `if` block isn't being executed? All it does is to create a string object that's never used. – yshavit May 02 '14 at 06:36
  • @yshavit I know it because in debug mode it doesnt create any variable named i – tolgazinho May 02 '14 at 06:39
  • Okay. Can you also confirm that the `char[]` for each string is the same? `string.toCharArray()`. It could also be that your debugger never shows the `i` variable because it goes out of scope as soon as it's created. That is, if the debugger is on that `String i =...` line, then `i` doesn't yet exist yet. Then you advance one line, and `i` has gone out of scope anymore. – yshavit May 02 '14 at 06:41
  • `i` is unused in the code so the compiler might remove that statement. You should insert a print statement in there to be sure. Either that or put a breakpoint and step through it. What debug does with an unused variable doesn't really tell you much about whether the block is executed. – Radiodef May 02 '14 at 06:41
  • @Radiodef B i is showed if I delete this if part. Which means, I believe even If I dont use it, debug mode shows it – tolgazinho May 02 '14 at 06:44
  • By deleting the `if`, though, you're probably also deleting the `{ ... }` scope that makes up the `if`'s body. That means that `i` doesn't go out of scope, which is why you can see it. Try removing the `if` but _not_ the curly braces: `{String i="der Name ist(" + val[0]+ ")";}`. Do you get the same results (not seeing `i`)? – yshavit May 02 '14 at 06:46
  • 1
    When in doubt, put a print statement. If you print `i`, the compiler is not allowed to remove the statement. – Radiodef May 02 '14 at 06:47
  • Can you differentiate b/w {0 and O} ? – Deepu--Java May 02 '14 at 06:48
  • @yshavit it's being used but outside of "if" . Still if statement doesnt work – tolgazinho May 02 '14 at 06:59
  • @tolgazinho - Try printing the ahshcode of both strings and then check their value. – TheLostMind May 02 '14 at 07:13
  • @tolgazinho Another thing you can try in debug mode is use right click --> inspect to look at exactly what `a`, `b`, and `a.equals(b)` are. – awksp May 02 '14 at 07:26

1 Answers1

0

Try

String a=val[0]; //Ensure value is 000 not OOO 
a = a.replaceAll("[\n\r]", "");
if(a.trim().equals(b.trim())){
 //toDO
}
Deepu--Java
  • 3,742
  • 3
  • 19
  • 30