title: How do I compare values against my database?
body: <p>In my application, I'm  inserting the user visit apps package name from Google Play and save it in a database.  I display only that apps from install apps that package name are in database.</p>
  
  <p>The values insert successfully into the database, but when I compare in the <code>PlayStoreApps</code>class at this line    <code>if (arraylist.equals(p.packageName))</code>:</p>
  
  <pre><code>public class PlayStoreApps extends Activity implements OnItemClickListener {
  
      private static final boolean INCLUDE_SYSTEM_APPS = false;
      DatabaseHandler db;
      private ListView mAppsList;
      private AppListAdapter mAdapter;
      private List&lt;App&gt; mApps;
  
      db = new DatabaseHandler(this);
  
      private List&lt;App&gt; loadInstalledApps(boolean includeSysApps) {
          List&lt;App&gt; apps = new ArrayList&lt;App&gt;();
  
          // the package manager contains the information about all installed apps
          PackageManager packageManager = getPackageManager();
  
          List&lt;PackageInfo&gt; packs = packageManager.getInstalledPackages(0); 
          List arraylist = db.getAllApps();
  
          for (int i = 0; i &lt; packs.size(); i++) {
              PackageInfo p = packs.get(i);
              ApplicationInfo applicationInfo = p.applicationInfo;
  
              if (arraylist.equals(p.packageName)) {
                  // if ( (p.packageName).equals(arraylist))
                  App app = new App();
                  app.setTitle(p.applicationInfo.loadLabel(packageManager).toString());
                  app.setPackageName(p.packageName);
                  app.setVersionName(p.versionName);
                  app.setVersionCode(p.versionCode);
                  CharSequence description = p.applicationInfo.loadDescription(packageManager);
                  app.setDescription(description != null ? 
                  description.toString() : "");
                  apps.add(app);
              }
          }
          return apps;
      }
  
      public class Search extends Activity {
          /** Called when the activity is first created. */
          DatabaseHandler db;
          WebView web;
          @Override
          public void onCreate(Bundle savedInstanceState) {
              super.onCreate(savedInstanceState);
              setContentView(R.layout.search);
              db = new DatabaseHandler(this);
  
              String id= url.substring(Standard .length(), url.indexOf("&amp;"));
              db.addContact(new Contact(id));
  
              Log.d("Reading: ", "Reading all contacts..");
              List&lt;Contact&gt; contacts = db.getAllContacts();       
  
              for (Contact cn : contacts) {
                  String log = "Id: "+cn.getID()+" ,Name: " + cn.getName() ;
  
                  //  String log = "Id: "+cn.getID()+" ,Name: " + cn.getName() + " ,Phone: " + cn.getPhoneNumber();
                  // Writing Contacts to log
                  Log.d("Name: ", log);
              }   
  
              view.loadUrl(url);
  
              return true;
          }
  
  public class DatabaseHandler extends SQLiteOpenHelper {
  
      private static final int DATABASE_VERSION = 1;
  
      private static final String DATABASE_NAME = "contactsManager";
  
      private static final String TABLE_CONTACTS = "contacts";
  
      private static final String KEY_ID = "id";
      private static final String KEY_NAME = "name";
  
      public DatabaseHandler(Context context) {
          super(context, DATABASE_NAME, null, DATABASE_VERSION);
      }
  
      // Creating Tables
      @Override
      public void onCreate(SQLiteDatabase db) {
      //  String CREATE_CONTACTS_TABLE = "CREATE TABLE " + TABLE_CONTACTS + "("+ KEY_ID + " INTEGER PRIMARY KEY," + KEY_NAME + " TEXT,"+ KEY_PH_NO + " TEXT" + ")";
  
          String CREATE_CONTACTS_TABLE = "CREATE TABLE " + TABLE_CONTACTS + "("+ KEY_ID + " INTEGER PRIMARY KEY," + KEY_NAME + " TEXT" +  " UNIQUE " + ")";
  
          db.execSQL(CREATE_CONTACTS_TABLE);
      }
  
      // Upgrading database
      @Override
      public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
          // Drop older table if existed
          db.execSQL("DROP TABLE IF EXISTS " + TABLE_CONTACTS);
  
          // Create tables again
          onCreate(db);
      }
  
      /**
       * All CRUD(Create, Read, Update, Delete) Operations
       */
  
      // Adding new contact
      void addContact(Contact contact) {
          SQLiteDatabase db = this.getWritableDatabase();
  
          ContentValues values = new ContentValues();
          values.put(KEY_NAME, contact.getName()); // Contact Name
      //  values.put(KEY_PH_NO, contact.getPhoneNumber()); // Contact Phone
  
          // Inserting Row
          db.insert(TABLE_CONTACTS, null, values);
          db.close(); // Closing database connection
      }
  
      // Getting single contact
      Contact getContact(int id) {
          SQLiteDatabase db = this.getReadableDatabase();
  
          Cursor cursor = db.query(TABLE_CONTACTS, new String[] { KEY_ID, KEY_NAME }, KEY_ID + "=?", new String[] { String.valueOf(id) }, null, null, null, null);
          if (cursor != null)
              cursor.moveToFirst();
  
          Contact contact = new Contact(Integer.parseInt(cursor.getString(0)), cursor.getString(1));
          // return contact
          return contact;
      }
  
      // Getting All Contacts
      public List&lt;Contact&gt; getAllContacts() {
          List&lt;Contact&gt; contactList = new ArrayList&lt;Contact&gt;();
          // Select All Query
          String selectQuery = "SELECT  * FROM " + TABLE_CONTACTS;
  
          SQLiteDatabase db = this.getWritableDatabase();
          Cursor cursor = db.rawQuery(selectQuery, null);
  
          // looping through all rows and adding to list
          if (cursor.moveToFirst()) {
              do {
                  Contact contact = new Contact();
                  contact.setID(Integer.parseInt(cursor.getString(0)));
                  contact.setName(cursor.getString(1));
                  //contact.setPhoneNumber(cursor.getString(2));
                  // Adding contact to list
                  contactList.add(contact);
              } while (cursor.moveToNext());
          }
  
          // return contact list
          return contactList;
      }
  
      // Updating single contact
      public int updateContact(Contact contact) {
          SQLiteDatabase db = this.getWritableDatabase();
  
          ContentValues values = new ContentValues();
          values.put(KEY_NAME, contact.getName());
  //  values.put(KEY_PH_NO, contact.getPhoneNumber());
  
          // updating row
          return db.update(TABLE_CONTACTS, values, KEY_ID + " = ?", new String[] { String.valueOf(contact.getID()) });
      }
  
      // Deleting single contact
      public void deleteContact(Contact contact) {
          SQLiteDatabase db = this.getWritableDatabase();
          db.delete(TABLE_CONTACTS, KEY_ID + " = ?", new String[] { String.valueOf(contact.getID()) });
          db.close();
      }
  
      public int deleteContact() {
          try {
              SQLiteDatabase db = this.getWritableDatabase();
              return db.delete(TABLE_CONTACTS, null, null);
          } catch (Exception e) {
              e.printStackTrace();
          }
          return 0;
      }
  
      // Getting contacts Count
      public int getContactsCount() {
          String countQuery = "SELECT  * FROM " + TABLE_CONTACTS;
          SQLiteDatabase db = this.getReadableDatabase();
          Cursor cursor = db.rawQuery(countQuery, null);
          cursor.close();
  
          // return count
          return cursor.getCount();
      }
  
      public ArrayList&lt;String&gt; getAllApps() {
  
          String selectQuery = "SELECT  * FROM "+TABLE_CONTACTS;
          ArrayList&lt;String&gt; apps = new ArrayList&lt;String&gt;();
          SQLiteDatabase db = this.getWritableDatabase();
          Cursor cursor = db.rawQuery(selectQuery, null);
  
          // looping through all rows and adding to list
          if (cursor.moveToFirst()) {
              do {
                  apps.add(cursor.getString(cursor.getColumnIndex(KEY_NAME)));
              } while (cursor.moveToNext());
          }
  
          // return list
          return apps;
      }
  }
  </code></pre>