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,031
  • 13
  • 51
  • 64
abhishek
  • 287
  • 1
  • 5
  • 28
  • Possible duplicate of [How do I compare strings in Java?](http://stackoverflow.com/questions/513832/how-do-i-compare-strings-in-java) – Blobonat 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
  • 10,575
  • 9
  • 71
  • 81
sunny
  • 11
  • 1
0

Use equals instead of ==.

For example :

if(word.equals("")){
    //result
}
dvhh
  • 4,663
  • 28
  • 32
Krzysztof Krasoń
  • 25,163
  • 16
  • 85
  • 109