String methods
All String Methods and their examples in Java
Substring charat indexof toLowercase etc
package StringDemo; public class StringDemo { public static void main(String [] args) { String firstName= "Venugopal"; String middleName= "Acharya"; String lastName= "Darur"; System.out.println("Name of the Person:\n"+ firstName+ " "+middleName+" "+lastName); String fullName=firstName+ " "+middleName+" "+lastName; System.out.println(fullName.substring(0)); System.out.println(fullName.substring(0,12)); System.out.println(fullName.substring(9,12)); System.out.println(fullName.substring(10 )); System.out.println("~~~~~~~~~~~~~~~~~~~~\n"+fullName); fullName=fullName.substring(10 ); System.out.println("~~~~~~~~~~~~~~~~~~~~\n"+fullName); System.out.println("~~~~~~~~~~~~~~~~~~~~\n"+fullName.substring(0,4)); fullName=fullName.replace('c', 'X'); System.out.println("`````````````````````After Replace`````````````````````\n"+fullName); fullName=fullName.replace('X', 'R'); System.out.println("`````````````````````After Replace`````````````````````\n"+fullName); fullName=fullName.replaceAll("ARharya", "Arun"); System.out.println("''''''''''''''''''''After Replace ALL''''''''''''''''\n"+ fullName); String phrase= "Arun Respects Manohar, Manohar Respects Randeer, Randeer Respects Arun, All three Respect Mutually, They Respects to meet, They Respect gals"; System.out.println( "-----------------Phrases-----------------\n"+phrase ); phrase=phrase.replaceAll("Respect", "Love"); System.out.println( "-----------------Phrases-----------------\n"+phrase ); String lowerCasePhrase = phrase.toLowerCase(); System.out.println("Lower Case of this above Phrase\n"+ lowerCasePhrase); String upperCasePhrase = phrase.toUpperCase(); System.out.println("Upper Case of this above Phrase\n"+ upperCasePhrase); //index of System.out.println("index of LOVE "+ upperCasePhrase.indexOf("LOVE")); System.out.println( "Last index of LOVE " +upperCasePhrase.lastIndexOf("LOVE")); if(upperCasePhrase.indexOf("LOVE")>-1){ System.out.println("Please dont use Filthy Language"); } System.out.println("CHAR AT :\n"+ lowerCasePhrase.charAt(113)); //Equals example String word= "Manohar" ; if(word.equals("ManoHar")) { System.out.println("We have Manohar"); } else{ System.out.println("We do not have word Manohar"); } if(word.equalsIgnoreCase("ManoHar")) { System.out.println("We have Manohar"); } else{ System.out.println("We do not have word Manohar"); } byte [] words = lowerCasePhrase.getBytes(); for ( int i=0; i
Please send comments to
vgdarur.javafive@blogger.com
Copyright © 2008 - iForeRunner.com
http://www.iforerunner.com/