Arrays Notes

Arrays Notes

DSA learning thread: 1

  1. if we don't assign value to an integer array or (primitive types) the default value assigned is 0.

  2. If we don't assign value to the string array by default the value is “null”. it is a literal like none in Python.

  3. string str = null; is correct

  4. int a = null; is wrong

a primitive type is eg an integer, a character that cannot be broken down.

Data Types-

  • at compile time variable is created in stack memory and on run time memory is allocated in heap memory with the initialized size value.

  • Mutable objects = Values can be re-assigned post initialization. eg- arrays, lists, dictionaries

  • Immutable objects= cannot be re-assigned or changed once created. eg- tuples, strings.

2D-arrays- rows are manadatory as in heap it is stored as arrays inside array, In 2D array arrays are stored inside array.

each object inside array is a reference variable pointing to an object, just like arr pointing to array.

####size of row = array.length,

###size of col = row[i].length.

###2d array

  • psudo code- how to fill this array’s rows and columns-
  1. define arrays length - int [][] arr1 = new int [3][2]

  2. define for loop- till how many rows to fill = for(int i=0; i<arr1.length; i++)

  3. define for loop - how many cols to fill within each row = for(int j =0; j<arr[i].length; j++)

  4. working of loop- for each row(or i), iterating (all)each column inside, and filling the 2d array.

Subscribe to my newsletter

Read articles from directly inside your inbox. Subscribe to the newsletter, and don't miss out.

SUBSCRIBE

arraysJavaDSA

Shivani Paswan

WRITTEN BY

Shivani Paswan

Add Profile Bio

©2023 Shivani Paswan's Blog

Archive·Privacy policy·Terms

Publish with Hashnode

Powered by Hashnode - Home for tech writers and readers