SCJA String study preperation
Here is a short class I wrote to help with studying for the SCJA (section 4)... if anyone can add any other examples to it, please do.
publicclass strings{
publicstatic String scjaString ="This is the SCJA String Test! ";
publicstaticvoid main (String args[])
{
System.out.println (scjaString);
//startsWith
System.out.println (scjaString.startsWith("is",10));//ture
System.out.println (scjaString.startsWith("This"));//true
System.out.println (scjaString.startsWith("That"));//false
//endsWith
System.out.println (scjaString.endsWith("Test! "));//true
System.out.println (scjaString.endsWith("Test "));//false
//length
System.out.println (scjaString.length());//36
//substring
System.out.println (scjaString.substring(17,21));//SCJA
System.out.println (scjaString.substring(17));//SCJA String Test!
//trim
System.out.print (scjaString.trim());
System.out.println (scjaString.trim());
//This is the SCJA String Test!This is the SCJA String Test!
//indexOf
System.out.println(scjaString.indexOf('i'));//7
System.out.println(scjaString.indexOf("is"));//7
System.out.println(scjaString.indexOf("ing",10));//25
//charAt
System.out.println(scjaString.charAt(13));//t
//replace
System.out.println(scjaString.replace('A','P'));//This is the SCJP String Test!
System.out.println(scjaString.replace("This","That"));//That is the SCJA String Test!
}
}
Message was edited by:
javarob

