Java String and Array Handling with split() Method

📌 Strings, Arrays & split() in Java 🔹 String String is a class used to store a group of characters and is represented in double quotes (" "). 👉 Ways to create String: Using string literal String s = "Hello"; Using new keyword String s = new String("Hello"); 👉 Important points: Strings are immutable (cannot be changed) Stored in String Constant Pool (SCP) Using "new" → stored in heap memory Comparing objects → compares address Default value → null 🔹 String Methods Commonly used methods: length() → returns length of string toUpperCase() → converts to uppercase toLowerCase() → converts to lowercase charAt(index) → returns character equals() → compares two strings contains() → checks substring substring(start, end) → extracts part startsWith() → checks starting value endsWith() → checks ending value trim() → removes spaces 💻 Example: String s = "Hello Java"; System.out.println(s.length()); System.out.println(s.toUpperCase()); System.out.println(s.charAt(1)); 👉 Output: 10 HELLO JAVA e 🔹 split() Method Used to split a string into parts. 💻 Syntax: variable.split(" "); 💻 Example: String s = "Hi This is Java"; String[] words = s.split(" "); 👉 Output: Hi This is Java 🔹 Arrays Arrays are used to store multiple values of the same data type. 👉 Key points: Fixed size Same data type Stored in continuous memory Index starts from 0 💻 Syntax: int[] arr = new int[5]; 👉 Other ways: int[] arr = {1,2,3}; int arr[] = new int[5]; These concepts help in handling text data and storing multiple values efficiently in Java. #Java #CodingJourney #LearnJava #FullStackDeveloper

  • No alternative text description for this image

To view or add a comment, sign in

Explore content categories