0

I have this code where stringArray contains 1000 words and String[] a contains words which are split into two columns a[0] and a[1].

So, now a[0] contains all words and a[1] contains keys and I want to compare a[0] with another array. How should I do this?

String[] stringArray = swn.mylist.toArray(new String[0]);
String[] a = new String[stringArray.length+1];

for(String words: stringArray) {  
    a = words.split("#");
    System.out.println(a[0]);
}
River
  • 8,585
  • 14
  • 54
  • 67
abhishek
  • 301
  • 1
  • 5
  • 29
  • Possible duplicate of [How do I compare strings in Java?](http://stackoverflow.com/questions/513832/how-do-i-compare-strings-in-java) – CloudPotato Jul 14 '16 at 08:21

2 Answers2

1

I guess you are looking for this kind of code:

String[] stringArray = {"Hel#lo","Wel#come","Te#st","I#n","Ja#va"};
String[] a;

for (String words : stringArray) {
    a = words.split("#");
    System.out.println(a[0]);
}
Kurt Van den Branden
  • 11,995
  • 10
  • 76
  • 85
sunny
  • 11
  • 1
0

Use equals instead of ==.

For example :

if(word.equals("")){
    //result
}
dvhh
  • 4,724
  • 27
  • 33
Krzysztof Krasoń
  • 26,515
  • 16
  • 89
  • 115