In java programming there are many built-in string manipulation functions.These functions belong to java.lang packages. The Java program to demo built in function use of each commonly used string function .More details about string class will be discussed in our Java Programming Tutorial.
The program is written using NetBean 8.2 and you may also need to install the suitable Java SDK version for NetBean IDE. The operating system platform is Windows 7 64-bit system. The program is a very simple one and intended for beginners of Java programming.
Problem Definition
The program reads 3 string variables and then perform following operations on them.
- Find the length of the string using length () function.
- Convert the string into uppercase and lowercase using toUpperCase () and toLowerCase () functions respectively.
- Â Concatenate two strings using concat () function.
Flowchart
Program Code
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package JavaExamples;
/**
*
* @author Admin
*/
public class StringDemo {
public static void main(String[] args) {
int x, y;
String S = "Elephant";
String S1 = "Tiger";
String S3 = "Hello";
x = S.length();
y = S1.length();
System.out.println("Length of S=" + x);
System.out.println("Length of S1=" + y);
System.out.println(S.toUpperCase());
System.out.println(S.toLowerCase());
String S2 = S + S1;
System.out.println("S2=" + S2);
String S4 = S3.concat(S1);
System.out.println(S4);
}
}
Output
The output of the program is given below. It show the various forms of string variable – uppercase, lowercase, concatenated strings and length of strings.
Length of S=8
Length of S1=5
ELEPHANT
elephant
S2 = ElephantTiger
HelloTiger
Related Articles:-
- Program to read text using Bufferedreader in Java.
- Java Program demonstrating String-Buffer Class and String-Builder Class.
- Java program to demo Builtin String functions.