0

I have a String array containing " at start and at the end of string I wanted to remove it Below is the code i tried but its not working

String str="98900205670001613 jonh mathews        -66,822.60        65,000.00        65,000.00        -1,822.60    "
String[] tokens= new String[15];
tokens=line.split("\\s+");
tokens=replace(tokens,"\"","");

static String[] replace(String[] arr, String find, String replace) {
        for (int i = 0; i < arr.length; i++) {

            if (arr[i] == find) {
                arr[i] = replace;
            }
        }
        return arr;

    }
Wasim Wani
  • 555
  • 2
  • 11
  • 24
  • Define "not working" – Pshemo Apr 04 '15 at 15:53
  • 1
    Also about `arr[i] == find` read [How do I compare strings in Java?](http://stackoverflow.com/questions/513832/how-do-i-compare-strings-in-java). In short: try with `arr[i].equals(find)`. – Pshemo Apr 04 '15 at 15:53
  • After executing code the character " is still there in the string – Wasim Wani Apr 04 '15 at 15:54
  • @Eran Since you have marked it duplicate please post the link to original Question – Wasim Wani Apr 04 '15 at 15:56
  • Refresh your browser, you should see link above your question. – Pshemo Apr 04 '15 at 15:57
  • If i am not wrong its not a duplicate question. Its just i was not correctly comparing the strings properly. Unfair World – Wasim Wani Apr 04 '15 at 16:02
  • It is duplicate. Your code works fine for me if I replace `if (arr[i] == find) {` with `if (arr[i].equals(find)) {` (working example: http://ideone.com/GgLXdp). So it looks like problem may be related with how you are using this code, but we can't help you with that because we can't see your entire code. – Pshemo Apr 04 '15 at 16:39

0 Answers0