0% found this document useful (0 votes)
1 views2 pages

String Functions Practice

String functions
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views2 pages

String Functions Practice

String functions
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

STRING FUNCTIONS PRACTICE

String m="computer is fun";

int l=m.length();// 15

String s=m.substring(0,8);//computer

System.out.println(s);

String p=m.substring(12);//fun

System.out.println(p);

int k=m.lastIndexOf(' ');//11

String x=m.substring(k+1);//fun

String y=m.substring(k+1,m.length());//fun

System.out.println(y);

int r=m.indexOf(' ');//8

String t=m.substring(r+1,k);//is

System.out.println(t);

System.out.println("happy".equals("Happy"));//false

System.out.println("happy".equalsIgnoreCase("Happy"));//true

String m="silent";

String n="picture";

System.out.println(m.compareTo(n));//3

System.out.println(n.compareTo(m));//-3

System.out.println("discovery".compareTo("disturbed"));//-17

System.out.println("Mangoes".compareTo("mango"));//-32

System.out.println("exercise".compareTo("Exercise"));//32

System.out.println("Mangoes".compareToIgnoreCase("mango"));//2

System.out.println("computer science".charAt(4));
System.out.println("exercise".toUpperCase());

String y="computer science";

System.out.println(y.substring(9).toUpperCase());

System.out.println(Character.toLowerCase('Y'));//char

String m="centre";

String p=m.toUpperCase();//string

String t1=" hard work ";

String t2=" never ";

String t3=" Fails ";

System.out.println(t1.concat(t2).concat(t3));//string

System.out.println(t1+t2+t3);// string

System.out.println("good manners".replace('n','*'));// string

System.out.println("computer science".endsWith("ce"));//true

System.out.println("computer science".endsWith("Ce"));//false

System.out.println("computer science".endsWith("science"));//true

System.out.println("meenakshi@gmail.com".endsWith("@gmail.com"));//true

System.out.println("computer science".endsWith("computer science"));//true

System.out.println("computer science".endsWith("r science"));//true

System.out.println(" computer science ".trim().length());

System.out.println(" computer science ".length());

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy