0
char[] Char = {'a','b'};
String str = "ab";

String c = new String(Char);

if(str == c){
    System.out.println("working!");
}

I've converted the array "Char" to a String "c" but when i try to use it in the if-statement it's nor working. Nothing prints out and no erors.

Help please!

Uli Köhler
  • 13,012
  • 16
  • 70
  • 120

1 Answers1

0

You need to use equals() instead of == for Strings:

char[] Char = {'a','b'};
String str = "ab";

String c = new String(Char);

if(str.equals(c)){
    System.out.println("working!");
}
Uli Köhler
  • 13,012
  • 16
  • 70
  • 120