Download - ICS3U – String
![Page 1: ICS3U – String](https://reader035.vdocuments.mx/reader035/viewer/2022081420/568149d5550346895db6fe19/html5/thumbnails/1.jpg)
ICS3U – StringICS3U – StringTeacher: Mr. HoCourse URL: http://computerNHSS.wikispaces.com
![Page 2: ICS3U – String](https://reader035.vdocuments.mx/reader035/viewer/2022081420/568149d5550346895db6fe19/html5/thumbnails/2.jpg)
What is String in JavaWhat is String in JavaString is a data typeIt is a sequence of characters E.g.1, “Computer”E.g.2, “We love Computer
Science!”
![Page 3: ICS3U – String](https://reader035.vdocuments.mx/reader035/viewer/2022081420/568149d5550346895db6fe19/html5/thumbnails/3.jpg)
How to Use String in JavaHow to Use String in JavaFirst, declare a variable of String
type inside the main methodIn main():
String word = “Apple”;
![Page 4: ICS3U – String](https://reader035.vdocuments.mx/reader035/viewer/2022081420/568149d5550346895db6fe19/html5/thumbnails/4.jpg)
Built-in MethodsBuilt-in MethodsString word = “AppLe”;word.length(); // length of the wordword.charAt(3); // character at index 3word.substring(2, 4); // substringword.toUpperCase(); // upper caseword.toLowerCase(); // lower caseword.indexOf(‘p’); // first occurrence of ‘p’word.indexOf(“pp”); // first occurrence of “pp”word.lastIndexOf(‘p’); // last occurrence of ‘p’word.equals(“apple”); // Is “AppLe” equal
“apple”?word.equalsIgnoreCase(“apple”);
![Page 5: ICS3U – String](https://reader035.vdocuments.mx/reader035/viewer/2022081420/568149d5550346895db6fe19/html5/thumbnails/5.jpg)
word.length()word.length()
In the main() method: String word = “AppLe”; System.out.println(word.length());
Output:5
![Page 6: ICS3U – String](https://reader035.vdocuments.mx/reader035/viewer/2022081420/568149d5550346895db6fe19/html5/thumbnails/6.jpg)
word.charAt(3)word.charAt(3)
In the main() method: String word = “AppLe”; System.out.println(word.charAt(3));
Output:L
![Page 7: ICS3U – String](https://reader035.vdocuments.mx/reader035/viewer/2022081420/568149d5550346895db6fe19/html5/thumbnails/7.jpg)
word.substring(2, 4)word.substring(2, 4)
In the main() method: String word = “AppLe”; System.out.println(word.substring(2,4));
Output:pL
![Page 8: ICS3U – String](https://reader035.vdocuments.mx/reader035/viewer/2022081420/568149d5550346895db6fe19/html5/thumbnails/8.jpg)
word.toUpperCase()word.toUpperCase()
In the main() method: String word = “AppLe”; System.out.println(word.toUpperCase());
Output:APPLE
![Page 9: ICS3U – String](https://reader035.vdocuments.mx/reader035/viewer/2022081420/568149d5550346895db6fe19/html5/thumbnails/9.jpg)
word.toLowerCase()word.toLowerCase()
In the main() method: String word = “AppLe”; System.out.println(word.toLowerCase());
Output:apple
![Page 10: ICS3U – String](https://reader035.vdocuments.mx/reader035/viewer/2022081420/568149d5550346895db6fe19/html5/thumbnails/10.jpg)
word.indexOf(‘p’)word.indexOf(‘p’)
In the main() method: String word = “AppLe”; System.out.println(word.indexOf(‘p’));
Output:1
![Page 11: ICS3U – String](https://reader035.vdocuments.mx/reader035/viewer/2022081420/568149d5550346895db6fe19/html5/thumbnails/11.jpg)
word.indexOf(“pp”)word.indexOf(“pp”)In the main() method: String word = “AppLe”; System.out.println(word.indexOf(“pp”));
Output:1
![Page 12: ICS3U – String](https://reader035.vdocuments.mx/reader035/viewer/2022081420/568149d5550346895db6fe19/html5/thumbnails/12.jpg)
word.lastIndexOf(‘p’)word.lastIndexOf(‘p’)In the main() method: String word = “AppLe”; System.out.println(word.lastIndexOf(‘p’));
Output:2
![Page 13: ICS3U – String](https://reader035.vdocuments.mx/reader035/viewer/2022081420/568149d5550346895db6fe19/html5/thumbnails/13.jpg)
word.equals(“apple”)word.equals(“apple”)In the main() method: String word = “AppLe”; System.out.println(word.equals(“apple”));
Output:false
![Page 14: ICS3U – String](https://reader035.vdocuments.mx/reader035/viewer/2022081420/568149d5550346895db6fe19/html5/thumbnails/14.jpg)
word.equalsIgnoreCase(“appword.equalsIgnoreCase(“apple”)le”)In the main() method: String word = “AppLe”; System.out.println( word.equalsIgnoreCase(“apple”));
Output:true
![Page 15: ICS3U – String](https://reader035.vdocuments.mx/reader035/viewer/2022081420/568149d5550346895db6fe19/html5/thumbnails/15.jpg)
ClassworkClassworkGo to
http://computerNHSS.wikispaces.com
Download the classwork: ◦JBB_pg_16.pdf◦JBB_pg_17.pdf
Work on #1, 2, and 4