ITP

BSc IT - Structure Programming Methodology - Java

What is string ? what is substring ?

In : BSc IT Subject : Structure Programming Methodology - Java

A String in Java is a sequence of characters used to represent text. It is one of the most commonly used data types and is used to store words, sentences, or any kind of textual information.

In Java, strings are created using double quotes:
 
String name = "Hello Java";
 
trings are immutable , which means once created, their value cannot be changed.
 
A substring  is a part (or portion) of a string. You can extract a substring from a string by specifying the starting and ending positions (indexes). 

Java provides the substring() method for this: 
 
string.substring(startIndex, endIndex);
 
Example :
 
String str = "Hello Java";
String sub = str.substring(0, 5); // Extracts characters from index 0 to 4
System.out.println(sub); // Output: Hello

About us

A truly open platform where you may ask questions and get answers. We also provide comprehensive and easy-to-understand answers to question papers.  discover...

Site status

Flag Counter

Privacy Policy

Sitemap