Skip to main content

Chapter 9: Working with Arrays and Strings 📊

This cheat sheet covers arrays and string handling for Chapter 9 of the GSEB Std 12 Computer Studies syllabus.

🎯 Key Concepts

  • Array: A fixed-size collection of data of the same type stored in continuous memory.
  • String: An immutable object representing a sequence of characters.
  • Index: Position of an element (starts from 0).

🛠️ Java Arrays (1D & 2D)

1. 1D Array Syntax

  • Declaration: int[] marks;
  • Creation: marks = new int[5]; (Values initialized to 0 by default).
  • Access: marks[0] = 95;

2. 2D Array Syntax (Matrix)

  • Declaration: int[][] matrix = new int[2][3]; (2 rows, 3 columns).
  • Access: matrix[row][col].

3. The java.util.Arrays Helper Class

MethodDescription
Arrays.sort(arr)Sorts the array in ascending order.
Arrays.fill(arr, val)Fills the whole array with a single value.
Arrays.equals(arr1, arr2)Returns true if two arrays have same elements in same order.
Arrays.binarySearch(arr, key)Finds the index of an element (array must be sorted).

📜 Java Strings (Immutable)

1. Key Properties

  • Immutability: Once a String is created, its value cannot be changed.
  • String Pool: Efficient memory storage for literals.

2. Essential String Methods

MethodTypeDescription
length()MethodReturns the number of characters.
charAt(i)MethodReturns character at index i.
substring(start, end)MethodReturns part of string from start to end-1.
equals(other)MethodCase-sensitive equality check.
equalsIgnoreCase(other)MethodCase-insensitive equality check.
replace('o', 'a')MethodReplaces all 'o' with 'a'.

💡 Board Focus: High-Weightage Points 👔

  • MCQ Alert: length is a property for arrays (arr.length); length() is a method for strings (s.length()).
  • MCQ Alert: Index of the last element is always length - 1.
  • MCQ Alert: Array size cannot be changed after creation.
  • MCQ Alert: Calendar and Date classes are in the java.util package.
  • MCQ Alert: System.arraycopy() is used to copy arrays.

Board Exam Secret

GSEB often asks about the "Default Values" of arrays. Remember: int = 0, boolean = false, float/double = 0.0, and objects = null.


Std 12 Hub | [End of Series]

📍 Visit Us

🏫 VD Computer Tuition Surat

VD Computer Tuition
📍 Address
2/66 Faram Street, Rustompura
Surat395002, Gujarat, India
📞 Phone / WhatsApp
+91 84604 41384
🌐 Website

Computer Classes & Tuition — Areas We Serve in Surat

AdajanAlthanAmroliAthwaAthwalinesBhagalBhatarBhestanCanal RoadChowkCitylightDumasGaurav PathGhod Dod RoadHaziraJahangirpuraKamrejKapodraKatargamLimbayatMagdallaMajura GateMota VarachhaNanpuraNew CitylightOlpadPalPandesaraParle PointPiplodPunaRanderRing RoadRustampuraSachinSalabatpuraSarthanaSosyo CircleUdhnaVarachhaVed RoadVesuVIP Road
📞 Call Sir💬 WhatsApp Sir