String Handling in Java
Java is a popular programming language that is widely used in various industries. One of the essential features of Java is its string handling capabilities. In Java, strings are a sequence of characters that are used to store and manipulate text-based data. Java provides a vast range of string handling techniques that programmers can use to perform various operations on strings. In this article, we will discuss various string handling techniques in Java.
String Concatenation:
String concatenation is the process of combining two or more strings to form a single string. In Java, we can use the "+" operator to concatenate two or more strings.
Example:
String str1 = "Hello";
String str2 = "World";
String result = str1 + str2;
System.out.println(result); // Output: HelloWorld
String Length:
The length() method in Java returns the length of the string. It returns the number of characters present in the string, including white spaces.
Example:
String str = "Hello World";
int len = str.length();
System.out.println(len);
Output for the above program is as follows
11