Why my if statement if (tablename == Character.toString('S')) isn't signing up as true? Both print the be S... It is possible to different why I'm able to implement this? I possibly could perform a != but I have to increase the arguments to my if statement, and my tablename must 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 == Character.toString('S');

if (tablename == Character.toString('S')){

OUTPUT: Enter table: S S S false

Since you are evaluating both objects for equality, you should utilize:

if (tablename.equals(Character.toString('S'))) {

Here is a nice reference on equality comparison in java:


The == only pertains to the equality from the pointer that Character.toString() returns. Want to use the below.