today we had a class on string handling it was great ok now we will discuss about it
String a="Manpreet kaur";
String s1=new String(a);------------------passing a string to constructor
String s2=new String(s1);------------------ ,,
a.concat(b)----------------------------to cocatinate two strings
a.toUpperCase()---------------------convert all the characters to upper case
a.toLowerCase()---------------------convert all the characters to lower case
b.trim()--------------------------------trim is to remove extra spaces in the string
a.equals(c)----------------------------compare if two strings are equal or not its case sensitive
a.length()------------------------------to calculate the length of the string like in string "manpreet"=8
a.startsWith("M")--------------------passes true or false checking if the string is starting from M case sensitive
a.charAt(4)----------------------------gives the character present on 4th position (starting from 0)
a.equalsIgnoreCase()----------------compare the two string without concerning lower or upper case
a.indexOf('e')--------------------------search for the e occurring for the first time and ans the position (starting from 0)
a.lastIndexOf('e')---------------------searching for the last occurrence of e and return its position
(count starts fronm starting and starting from 0)
ONE EXAMPLE
import java.lang.String.*;
import java.io.*;
class String_fun
{
public static void main(String arg[])
{
try
{String num=new String("welcome");
String a="Manpreet kaur";
char ch[]=new char[7];
String s1=new String(a);
String s2=new String(s1);
System.out.println(s1);
System.out.println(s2);
String b=" jasleen kaur ",c="MANPREET KAUR";
System.out.println(a+" first string");////////////////////////////Manpreet kaur first string
System.out.println(b+" second string");//////////////////////// jasleen kaur second string
System.out.println(c+" third string");///////////////////////////MANPREET KAUR third string
System.out.println(a.concat(b)+"are friends");////////////////Manpreet kaur jasleen kaur are friends
System.out.println(a.toUpperCase()+" to upper case");///MANPREET KAUR to upper case
System.out.println(a.toLowerCase()+" to lower case");//manpreet kaur to lower case
System.out.println(b.trim()+" trim");//////////////////////////jasleen kaur
System.out.println(a.equals(c)+" without ignore case");//true
System.out.println(a.length()+" length of string");////////8
System.out.println(a.startsWith("M")+" string starting with M");//true
System.out.println(a.charAt(4)+" char at position 4");////////////////r
num.getChars(4,6,ch,0);
System.out.println(ch);//////////////////////////////////////////ree
}
catch(ArrayIndexOutOfBoundsException obj)
{}
}}
String a="Manpreet kaur";
String s1=new String(a);------------------passing a string to constructor
String s2=new String(s1);------------------ ,,
a.concat(b)----------------------------to cocatinate two strings
a.toUpperCase()---------------------convert all the characters to upper case
a.toLowerCase()---------------------convert all the characters to lower case
b.trim()--------------------------------trim is to remove extra spaces in the string
a.equals(c)----------------------------compare if two strings are equal or not its case sensitive
a.length()------------------------------to calculate the length of the string like in string "manpreet"=8
a.startsWith("M")--------------------passes true or false checking if the string is starting from M case sensitive
a.charAt(4)----------------------------gives the character present on 4th position (starting from 0)
a.equalsIgnoreCase()----------------compare the two string without concerning lower or upper case
a.indexOf('e')--------------------------search for the e occurring for the first time and ans the position (starting from 0)
a.lastIndexOf('e')---------------------searching for the last occurrence of e and return its position
(count starts fronm starting and starting from 0)
ONE EXAMPLE
import java.lang.String.*;
import java.io.*;
class String_fun
{
public static void main(String arg[])
{
try
{String num=new String("welcome");
String a="Manpreet kaur";
char ch[]=new char[7];
String s1=new String(a);
String s2=new String(s1);
System.out.println(s1);
System.out.println(s2);
String b=" jasleen kaur ",c="MANPREET KAUR";
System.out.println(a+" first string");////////////////////////////Manpreet kaur first string
System.out.println(b+" second string");//////////////////////// jasleen kaur second string
System.out.println(c+" third string");///////////////////////////MANPREET KAUR third string
System.out.println(a.concat(b)+"are friends");////////////////Manpreet kaur jasleen kaur are friends
System.out.println(a.toUpperCase()+" to upper case");///MANPREET KAUR to upper case
System.out.println(a.toLowerCase()+" to lower case");//manpreet kaur to lower case
System.out.println(b.trim()+" trim");//////////////////////////jasleen kaur
System.out.println(a.equals(c)+" without ignore case");//true
System.out.println(a.length()+" length of string");////////8
System.out.println(a.startsWith("M")+" string starting with M");//true
System.out.println(a.charAt(4)+" char at position 4");////////////////r
num.getChars(4,6,ch,0);
System.out.println(ch);//////////////////////////////////////////ree
}
catch(ArrayIndexOutOfBoundsException obj)
{}
}}
No comments:
Post a Comment