How come my if statement if (tablename == Character.toString('S')) is not registering as true? Both print out the be S… Is there a different why I can implement this? I could do a != but I need to add more arguments to my if statement, and my tablename needs to stay a string.
System.out.println("Enter table:");
String line = input.readLine();
StringTokenizer tk = new StringTokenizer(line);
String tablename = tk.nextToken();
DatabaseMetaData d = conn.getMetaData();
ResultSet rm = d.getColumns(null, null, tablename, null);
System.out.println(tablename);
System.out.println(Character.toString('S');
System.out.println(tablename == Character.toString('S');
if (tablename == Character.toString('S')){
System.out.println("Woot!");
}
OUTPUT:
Enter table:
S
S
S
false
Since you’re comparing both objects for equality, you need to use:
Here’s a nice reference on equality comparison in java:
http://leepoint.net/notes-java/data/expressions/22compareobjects.html