Please disable adblock to view this page.

← Go home

String Operations in Java


April 30, 2017
Published By : Pratik Kataria
Categorised in:

Understanding through Code

public class StringOps {
	public static void main( String[] args ){

		String str1 = "Hello this is AI talking.";
		System.out.println("Length of string: " +str1.length());

		System.out.println("Position (Index) of substring: " +str1.indexOf("AI"));

		String substr = str1.substring(14); //for verification

		String str2 = "Aloha          "; //string with spaces
		System.out.println("Length of string with spaces: " +str2.length());

		String str3 = str2.trim();  //removes whitespace




  • Length of string: 25
  • Position (Index) of substring: 14
  • AI talking.
  • Length of string with spaces: 15
  • 5


Pratik Kataria is currently learning Springboot and Hibernate.
Technologies known and worked on: C/C++, Java, Python, JavaScript, HTML, CSS, WordPress, Angular, Ionic, MongoDB, SQL and Android.
Softwares known and worked on: Adobe Photoshop, Adobe Illustrator and Adobe After Effects.