Basic example using String Function in Java


Here is the simple program for printing basic example using string function in Java.

Source Code

import java.io.*;
import java.util.Scanner;
class strings
{
  public static void main(String args[])
  {
   String a;
   String b="ram"; 
   System.out.print("\nEnter The String:");
   Scanner in = new Scanner(System.in);
   a=in.nextLine();//Ram
   System.out.print("\nOriginal String   :"+a); //Ram
   System.out.print("\nLower Case        :"+a.toLowerCase()); //ram
   System.out.print("\nUpper Case        :"+a.toUpperCase()); //RAM
   System.out.print("\nReplace           :"+a.replace('a','u')); //RuM
   System.out.print("\nTrim              :"+b.trim());//sam
   System.out.print("\nEquals            :"+a.equals(b));//False
   System.out.print("\nNo Case Equals    :"+a.equalsIgnoreCase(b));//False
   System.out.print("\nLength		 :"+a.length());//3
   System.out.print("\nCharAt		 :"+a.charAt(2));//M
   System.out.print("\nCompare	         :"+a.compareTo(b));//False
   System.out.print("\nConcat	         :"+a.concat(b));//RuMsam
   System.out.print("\nSubstring 	 :"+a.substring(2));//sam
   System.out.print("\nSubstring 	 :"+a.substring(0,2));//Ru
  }
}
To download raw file Click Here

Output

Enter The String  :Tutor
Original String   :Tutor
Lower Case        :tutor
Upper Case        :TUTOR
Replace           :Tutor
Trim              :ram
Equals            :false
No Case Equals    :false
Length            :5
CharAt            :t
Compare           :-30
Concat            :Tutorram
Substring         :tor
Substring         :Tu


Learn All in Tamil © Designed & Developed By Tutor Joes