Tuesday, 7 July 2015

Simple function to concatenate 'n' number of JSONArrays



private JSONArray concatJSONArray(JSONArray... arrs) throws JSONException {
    JSONArray result = new JSONArray();
    for (JSONArray arr : arrs) {
        for (int i = 0; i < arr.length(); i++) {
            result.put(arr.get(i));
        }
    }
    return result;


Example: JSONArray result= concatJSONArray(JSONArray array1,JSONArray array2);

Difference between Process and Thread.


Process
  • A process is an executing instance of an application.
  • A process is always stored in the main memory also termed as the primary memory .
  • A process can consists of multiple threads.
  • A process has a virtual address space, executable code, open handles to system objects, a security context, a unique process identifier, environment variables, a priority class, minimum and maximum working set sizes, and at least one thread of execution.
  • Each process is started with a single thread, often called the primary thread, but can create additional threads from any of its threads.
Threads

  •  A thread is a path of execution within a process ie, A thread is a subset of the process.
  •  All threads of a process share its virtual address space and system resources.
  • Normally threads are used for small tasks
  •  It is termed as a ‘lightweight process