Empty ArrayList equals null

No. An ArrayList can be empty (or with nulls as items) an not be null. It would be considered empty. You can check for am empty ArrayList with: ArrayList arrList = new ArrayList(); if(arrList.isEmpty()) { // Do something with the empty list here. } Or if you want to create a method that checks for … Read more

Correct way to synchronize ArrayList in java

You’re synchronizing twice, which is pointless and possibly slows down the code: changes while iterating over the list need a synchronnization over the entire operation, which you are doing with synchronized (in_queue_list) Using Collections.synchronizedList() is superfluous in that case (it creates a wrapper that synchronizes individual operations). However, since you are emptying the list completely, … Read more

How to use ArrayList.addAll()?

Collections.addAll is what you want. Collections.addAll(myArrayList, ‘+’, ‘-‘, ‘*’, ‘^’); Another option is to pass the list into the constructor using Arrays.asList like this: List<Character> myArrayList = new ArrayList<Character>(Arrays.asList(‘+’, ‘-‘, ‘*’, ‘^’)); If, however, you are good with the arrayList being fixed-length, you can go with the creation as simple as list = Arrays.asList(…). Arrays.asList … Read more

How can I create a list Array with the cursor data in Android

Go through every element in the Cursor, and add them one by one to the ArrayList. ArrayList<WhateverTypeYouWant> mArrayList = new ArrayList<WhateverTypeYouWant>(); for(mCursor.moveToFirst(); !mCursor.isAfterLast(); mCursor.moveToNext()) { // The Cursor is now set to the right position mArrayList.add(mCursor.getWhateverTypeYouWant(WHATEVER_COLUMN_INDEX_YOU_WANT)); } (replace WhateverTypeYouWant with whatever type you want to make a ArrayList of, and WHATEVER_COLUMN_INDEX_YOU_WANT with the column index … Read more