Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does this Java return statement mean?

Tags:

java

android

Am looking over some snippets of code and have come across a return statement which I've never seen before. What does it mean?

return checkDB != null ? true : false;

Here's the whole method code, for reference:

private boolean checkDataBase(){
        SQLiteDatabase checkDB = null;
        try{
            String pathToDB = dbPath + dbName;
            checkDB = SQLiteDatabase.openDatabase(pathToDB, null, SQLiteDatabase.OPEN_READONLY);
        }catch(SQLiteException e){
            //database does't exist yet.
        }
        if(checkDB != null){
            checkDB.close();
        }
        return checkDB != null ? true : false;
    }
like image 503
james246 Avatar asked Dec 10 '22 07:12

james246


1 Answers

The same as return checkDB != null

?: is a "ternary operator" which. Example: a ? b : c does the same as a method with this body: { if(a) { return b; } else { return c; } }

like image 183
Aaron Digulla Avatar answered Jan 03 '23 05:01

Aaron Digulla