SlideShare una empresa de Scribd logo
1 de 62
Descargar para leer sin conexión
Strings and Strings Manipulation
Contents ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Contents (2) ,[object Object],[object Object],[object Object]
What Is String?
What Is String? ,[object Object],[object Object],[object Object],[object Object],[object Object],String s = "Hello, Java"; s H e l l o , J a v a
java.lang.String ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
java.lang.String  (2) ,[object Object],[object Object],[object Object],[object Object],[object Object],String s = "Hello!"; int len = s. l ength () ; // len = 6 char ch = s .charAt(1) ; // ch = 'e' index = s.charAt(index) = 0 1 2 3 4 5 H e l l o !
Strings – First Example String s = &quot;Stand up, stand up, Balkan superman.&quot;; System.out.printf(&quot;s = amp;quot;%samp;quot;%n&quot;, s); System.out.printf(&quot;s. l ength ()  = %d%n&quot;, s.length()); for (int i = 0; i < s.length(); i++) { System.out.printf(&quot;s[%d] = %c%n&quot;, i, s.charAt(i)); }
Strings – First Example Live Demo
Declaring, Creating, Reading and Printing Creating and Using Strings
Declaring Strings ,[object Object],String str;
Creating Strings ,[object Object],[object Object],[object Object],[object Object],[object Object]
Creating Strings (2) ,[object Object],[object Object],[object Object],[object Object],S tring s;  // s  is  equal to null St ring s  = &quot;I am string literal!&quot;; S tring s 2 = s; String s = &quot;I'm &quot; + 42 + &quot; years old.&quot;;
Reading And Printing Strings ,[object Object],[object Object],String s = input.nextLine(); ,[object Object],[object Object],System.out.print(&quot;Please enter your name: &quot;);  String name = input.nextLine(); System.out.printf(&quot;Hello, %s!%n&quot;, name);
Live Demo Reading and Printing Strings
Manipulating Strings Comparing, Concatenating, Searching, Extracting Substrings, Splitting
Comparing Strings ,[object Object],[object Object],[object Object],[object Object],int result = str1.compareToIgnoreCase(str2); // result == 0 if str1 equals str2 // result < 0 if str1 if before str2 // result > 0 if str1 if after str2 str1.compareTo(str2);
Comparing Strings (2) ,[object Object],[object Object],[object Object],[object Object],if (str1.equalsIgnoreCase(str2)){ … } if (str1.equals(str2)){ … }
Comparing Strings (3) ,[object Object],[object Object],[object Object],String str1 = new String(&quot;Hello&quot;); String str2 = str1; System.out.println((str1==str2)); // true String str1 = &quot;Hello&quot;; String str2 = &quot;Hello&quot;; System.out.println((str1==str2)); // true !!! String str1 = new String(&quot;Hello&quot;); String str2 = new String(&quot;Hello&quot;); System.out.println((str1==str2)); // This is false !
Comparing Strings – Example  ,[object Object],String[] towns = {&quot;Sofia&quot;, &quot;Varna&quot;, &quot;Plovdiv&quot;, &quot;Pleven&quot;, &quot;Bourgas&quot;, &quot;Rousse&quot;, &quot;Yambol&quot;}; String firstTown = towns[0]; for (int i=1; i<towns. l ength; i++) { String currentTown = towns[i]; if (currentTown.compareTo(firstTown) < 0) { firstTown = currentTown; } } System.out.println(&quot;First town: &quot; + firstTown);
Comparing Strings Live Demo
Concatenating Strings ,[object Object],[object Object],[object Object],[object Object],S tring str =  str1. c oncat(str2);   String str = str1 + str2 + str3; String str += str1; S tring  n ame = &quot; Peter &quot;; int   age  =  22 ; S tring  s  =  name  + &quot; &quot; +  age ;  //    &quot;Peter 22&quot;
Concatenating Strings – Example String firstName = &quot;Svetlin&quot;; String lastName = &quot;Nakov&quot;; String fullName = firstName + &quot; &quot; + lastName; System.out.println(fullName); int age = 2 6 ; String nameAndAge = &quot;Name: &quot; + fullName +    &quot;Age: &quot; + age; System.out.println(nameAndAge); // Name: Svetlin Nakov // Age: 2 6
Concatenating Strings Live Demo
Searching Strings ,[object Object],[object Object],[object Object],[object Object],[object Object],i ndexOf( S tring str) i ndexOf( S tring str, int  from Index) l astIndexOf( S tring) lastIndexOf(String, int fromIndex)
Searching Strings – Example String str = &quot;Java Programming Course&quot;; int index = str.indexOf(&quot;Java&quot;); // index = 0 index = str.indexOf(&quot;Course&quot;); // index = 17 index = str.indexOf(&quot;COURSE&quot;); // index = -1 // indexOf is case sensetive. -1 means not found index = str.indexOf(&quot;ram&quot;); // index = 9 index = str.indexOf(&quot;r&quot;); // index = 6 index = str.indexOf(&quot;r&quot;, 7); // index = 9 index = str.indexOf(&quot;r&quot;, 10); // index = 20 i = s.charAt(i) = 0 1 2 3 4 5 6 7 8 9 10 11 12 … J a v a P r o g r a m m …
Searching Strings Live Demo
Extracting Substrings ,[object Object],[object Object],[object Object],[object Object],S tring filename = &quot;C: ics ila2005.jpg&quot;; S tring name = filename. s ub s tring(8,  16 ); // name is Rila2005 S tring filename = &quot;C: ics ummer2005.jpg&quot;; S tring nameAndExtension = filename. s ub s tring(8); // nameAndExtension is Rila2005 .jpg 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 C :   P i c s  R i l a 2 0 0 5 . j p g
Extracting Substrings Live Demo
Splitting Strings ,[object Object],[object Object],[object Object],String[] split(String regex) String[] parts = &quot;Ivan; Petar,Gosho&quot;.split(&quot;[;,]&quot;); // this wil separate the stirng into three parts // &quot;Ivan&quot;, &quot; Petar&quot; and &quot;Gosho&quot;
Splitting Strings - Example String listOfBeers =  &quot;Amstel, Zagorka, Tuborg, Becks.&quot;; String[] beers = listOfBeers.split(&quot;[ ,.]&quot;); System.out.println(&quot;Available beers are:&quot;); for (String beer : beers) { if (!&quot;&quot;.equalsIgnoreCase(beer)) { System.out.println(beer); } }
Splitting Strings Live Demo
Other String Operations Replacing Substrings, Changing Character Casing, Trimming
Replacing Substrings ,[object Object],[object Object],String cocktail = &quot;Vodka + Martini + Cherry&quot;; String replaced = cocktail.replace(&quot;+&quot;, &quot;and&quot;); // Vodka and Martini and Cherry
Changing Character Casing ,[object Object],[object Object],S tring alpha = &quot;aBcDeFg&quot;; S tring lowerAlpha = alpha. t oLower Case ();   //   abcdefg System.out.println(lowerAlpha); S tring alpha = &quot;aBcDeFg&quot;; S tring upper A lpha = alpha. t oUpper Case ();   //  ABCDEFG System.out.println(upperAlpha);
Trimming White Space ,[object Object],String s = &quot;  example of white space  &quot;; String clean = s.trim(); System.out.println(clean);
Other String Operations Live Demo
Building and Modifying Strings Using  StringBuilder  C lass
Constructing Strings ,[object Object],[object Object],[object Object],[object Object],public  static s tring  d upChar(char ch, int count){ S tring result = &quot;&quot;; for (int i=0; i<count; i++) result += ch; return result; } Bad practice. Avoid this!
Changing the Contents of a String –  StringBuilder ,[object Object],[object Object],public static String  r everseIt(String s) { StringBuilder sb = new StringBuilder(); for (int i = s.length()-1; i >= 0; i--) sb.append(s.charAt(i)); return sb.ToString(); }
The  StringBuilde r Class ,[object Object],[object Object],StringBuilder : length() = 11 capacity() = 15 used buffer (length()) unused buffer Capacity H e l l o , J a v a !
The  StringBuilde r Class (2) ,[object Object],[object Object],[object Object],[object Object],[object Object]
The  StringBuilde r Class (3) ,[object Object],[object Object],[object Object],[object Object],[object Object]
StringBuilder  – Example ,[object Object],public static String extractCapitals(String s) { StringBuilder result = new StringBuilder(); for (int i = 0; i < s.length(); i++) { char ch = s.charAt(i); if (Character.isUpperCase(ch)) { result.append(ch); } } return result.toString(); }
How the  +  Operator Does String Concatenations? ,[object Object],[object Object],[object Object],[object Object],String result = str1 + str2; StringBuffer sb = new StringBuffer(); sb. a ppend(str1); sb. a ppend(str2); S tring result = sb. t oString();
Using  StringBuilder Live Demo
Formatting Strings Using  t oString()  and  String. f ormat()
Method  toString() ,[object Object],[object Object],[object Object]
Method  String.format() ,[object Object],[object Object],[object Object],String template = &quot;If I were %s, I would %s.&quot;; String sentence1 = String.format( template, &quot;developer&quot;, &quot;know Java&quot;); System.out.println(sentence1); // If I were developer, I would know  Java . String sentence2 = String.format( template, &quot;elephant&quot;, &quot;weigh 4500 kg&quot;); System.out.println(sentence2); // If I were elephant, I would weigh 4500 kg.
Formatting Dates ,[object Object],[object Object],[object Object],[object Object],[object Object],Date  now  = (new GregorianCalendar()).getTime(); System.out.printf(&quot;Now is &quot; +  &quot;%1$td.%1$tm.%1$tY %1$tH:%1$tM:%1$tS&quot;,  now ); // Now is 23.05.2006 21:09:32
Formatting Strings Live Demo
Summary ,[object Object],[object Object],[object Object],[object Object],[object Object]
Summary (2) ,[object Object],[object Object]
Exercises ,[object Object],[object Object]
Exercises (2) ,[object Object],[object Object],[object Object],We are living in a yellow submarine. We don't have anything else. Inside the submarine is very tight. So we are drinking all the day. We will move out of it in 5 days.
Exercises (3) ,[object Object],[object Object],We are living in a  <upcase> yellow submarine</upcase>. We don't have <upcase>anything</upcase>  else . We are living in a  YELLOW SUBMARINE . We don't have  ANYTHING  else.
Exercises (4) ,[object Object],[object Object],[protocol]://[server]/[resource]
Exercises (5) ,[object Object],[object Object],[object Object],We are living in a yellow submarine. We don't have anything else. Inside the submarine is very tight. So we are drinking all the day. We will move out of it in 5 days. We are living in a yellow submarine. We will move out of it in 5 days.
Exercises (6) ,[object Object],[object Object],[object Object],Microsoft announced its next generation Java compiler today. It uses advanced parser and special optimizer for the Microsoft JVM. ********* announced its next generation **** compiler today. It uses advanced parser and special optimizer for the ********* ***.
Exercises (7) ,[object Object],[object Object],[object Object]
Exercises (8) ,[object Object],[object Object]
Exercises (9) ,[object Object]

Más contenido relacionado

La actualidad más candente

Final JAVA Practical of BCA SEM-5.
Final JAVA Practical of BCA SEM-5.Final JAVA Practical of BCA SEM-5.
Final JAVA Practical of BCA SEM-5.Nishan Barot
 
Java - Packages Concepts
Java - Packages ConceptsJava - Packages Concepts
Java - Packages ConceptsVicter Paul
 
Java 8 - CJ
Java 8 - CJJava 8 - CJ
Java 8 - CJSunil OS
 
Java IO Streams V4
Java IO Streams V4Java IO Streams V4
Java IO Streams V4Sunil OS
 
Implementation Of String Functions In C
Implementation Of String Functions In CImplementation Of String Functions In C
Implementation Of String Functions In CFazila Sadia
 
Basic i/o & file handling in java
Basic i/o & file handling in javaBasic i/o & file handling in java
Basic i/o & file handling in javaJayasankarPR2
 
Java Basics
Java BasicsJava Basics
Java BasicsSunil OS
 
String and string buffer
String and string bufferString and string buffer
String and string bufferkamal kotecha
 
Java string handling
Java string handlingJava string handling
Java string handlingSalman Khan
 
Handling of character strings C programming
Handling of character strings C programmingHandling of character strings C programming
Handling of character strings C programmingAppili Vamsi Krishna
 
Collection v3
Collection v3Collection v3
Collection v3Sunil OS
 
String In C Language
String In C Language String In C Language
String In C Language Simplilearn
 
Regular Expressions in Java
Regular Expressions in JavaRegular Expressions in Java
Regular Expressions in JavaOblivionWalker
 
Java exception handling
Java exception handlingJava exception handling
Java exception handlingBHUVIJAYAVELU
 
Hibernate
Hibernate Hibernate
Hibernate Sunil OS
 

La actualidad más candente (20)

Final JAVA Practical of BCA SEM-5.
Final JAVA Practical of BCA SEM-5.Final JAVA Practical of BCA SEM-5.
Final JAVA Practical of BCA SEM-5.
 
Java - Packages Concepts
Java - Packages ConceptsJava - Packages Concepts
Java - Packages Concepts
 
Java 8 - CJ
Java 8 - CJJava 8 - CJ
Java 8 - CJ
 
Log4 J
Log4 JLog4 J
Log4 J
 
Java IO Streams V4
Java IO Streams V4Java IO Streams V4
Java IO Streams V4
 
Implementation Of String Functions In C
Implementation Of String Functions In CImplementation Of String Functions In C
Implementation Of String Functions In C
 
Basic i/o & file handling in java
Basic i/o & file handling in javaBasic i/o & file handling in java
Basic i/o & file handling in java
 
Java Basics
Java BasicsJava Basics
Java Basics
 
Java String
Java String Java String
Java String
 
String and string buffer
String and string bufferString and string buffer
String and string buffer
 
Java string handling
Java string handlingJava string handling
Java string handling
 
Handling of character strings C programming
Handling of character strings C programmingHandling of character strings C programming
Handling of character strings C programming
 
Java Fundamentals
Java FundamentalsJava Fundamentals
Java Fundamentals
 
C string
C stringC string
C string
 
Collection v3
Collection v3Collection v3
Collection v3
 
C++
C++C++
C++
 
String In C Language
String In C Language String In C Language
String In C Language
 
Regular Expressions in Java
Regular Expressions in JavaRegular Expressions in Java
Regular Expressions in Java
 
Java exception handling
Java exception handlingJava exception handling
Java exception handling
 
Hibernate
Hibernate Hibernate
Hibernate
 

Destacado (10)

C# String
C# StringC# String
C# String
 
C# Strings
C# StringsC# Strings
C# Strings
 
C# string concatenations in unity (Updated 2014/7/11)
C# string concatenations in unity (Updated 2014/7/11)C# string concatenations in unity (Updated 2014/7/11)
C# string concatenations in unity (Updated 2014/7/11)
 
Php String And Regular Expressions
Php String  And Regular ExpressionsPhp String  And Regular Expressions
Php String And Regular Expressions
 
Servlets
ServletsServlets
Servlets
 
String Handling
String HandlingString Handling
String Handling
 
Object-oriented Programming-with C#
Object-oriented Programming-with C#Object-oriented Programming-with C#
Object-oriented Programming-with C#
 
Oops concept on c#
Oops concept on c#Oops concept on c#
Oops concept on c#
 
Regular Expressions
Regular ExpressionsRegular Expressions
Regular Expressions
 
Java servlet life cycle - methods ppt
Java servlet life cycle - methods pptJava servlet life cycle - methods ppt
Java servlet life cycle - methods ppt
 

Similar a Strings v.1.1

String and string manipulation x
String and string manipulation xString and string manipulation x
String and string manipulation xShahjahan Samoon
 
String and string manipulation
String and string manipulationString and string manipulation
String and string manipulationShahjahan Samoon
 
Csphtp1 15
Csphtp1 15Csphtp1 15
Csphtp1 15HUST
 
Chapter 9 - Characters and Strings
Chapter 9 - Characters and StringsChapter 9 - Characters and Strings
Chapter 9 - Characters and StringsEduardo Bergavera
 
Java căn bản - Chapter9
Java căn bản - Chapter9Java căn bản - Chapter9
Java căn bản - Chapter9Vince Vo
 
16 strings-and-text-processing-120712074956-phpapp02
16 strings-and-text-processing-120712074956-phpapp0216 strings-and-text-processing-120712074956-phpapp02
16 strings-and-text-processing-120712074956-phpapp02Abdul Samee
 
Regular Expression
Regular ExpressionRegular Expression
Regular ExpressionBharat17485
 
13 Strings and Text Processing
13 Strings and Text Processing13 Strings and Text Processing
13 Strings and Text ProcessingIntro C# Book
 
0-Slot21-22-Strings.pdf
0-Slot21-22-Strings.pdf0-Slot21-22-Strings.pdf
0-Slot21-22-Strings.pdfssusere19c741
 
Strings in Python
Strings in PythonStrings in Python
Strings in Pythonnitamhaske
 
introduction to strings in c programming
introduction to strings in c programmingintroduction to strings in c programming
introduction to strings in c programmingmikeymanjiro2090
 

Similar a Strings v.1.1 (20)

M C6java7
M C6java7M C6java7
M C6java7
 
String and string manipulation x
String and string manipulation xString and string manipulation x
String and string manipulation x
 
String and string manipulation
String and string manipulationString and string manipulation
String and string manipulation
 
Csphtp1 15
Csphtp1 15Csphtp1 15
Csphtp1 15
 
Chapter 9 - Characters and Strings
Chapter 9 - Characters and StringsChapter 9 - Characters and Strings
Chapter 9 - Characters and Strings
 
Java căn bản - Chapter9
Java căn bản - Chapter9Java căn bản - Chapter9
Java căn bản - Chapter9
 
16 strings-and-text-processing-120712074956-phpapp02
16 strings-and-text-processing-120712074956-phpapp0216 strings-and-text-processing-120712074956-phpapp02
16 strings-and-text-processing-120712074956-phpapp02
 
Regular Expression
Regular ExpressionRegular Expression
Regular Expression
 
Ch09
Ch09Ch09
Ch09
 
Team 1
Team 1Team 1
Team 1
 
Week6_P_String.pptx
Week6_P_String.pptxWeek6_P_String.pptx
Week6_P_String.pptx
 
String notes
String notesString notes
String notes
 
13 Strings and Text Processing
13 Strings and Text Processing13 Strings and Text Processing
13 Strings and Text Processing
 
[ITP - Lecture 17] Strings in C/C++
[ITP - Lecture 17] Strings in C/C++[ITP - Lecture 17] Strings in C/C++
[ITP - Lecture 17] Strings in C/C++
 
0-Slot21-22-Strings.pdf
0-Slot21-22-Strings.pdf0-Slot21-22-Strings.pdf
0-Slot21-22-Strings.pdf
 
Strings in Python
Strings in PythonStrings in Python
Strings in Python
 
pps unit 3.pptx
pps unit 3.pptxpps unit 3.pptx
pps unit 3.pptx
 
14 strings
14 strings14 strings
14 strings
 
Input And Output
 Input And Output Input And Output
Input And Output
 
introduction to strings in c programming
introduction to strings in c programmingintroduction to strings in c programming
introduction to strings in c programming
 

Más de BG Java EE Course (20)

Rich faces
Rich facesRich faces
Rich faces
 
JSP Custom Tags
JSP Custom TagsJSP Custom Tags
JSP Custom Tags
 
Java Server Faces (JSF) - advanced
Java Server Faces (JSF) - advancedJava Server Faces (JSF) - advanced
Java Server Faces (JSF) - advanced
 
Java Server Faces (JSF) - Basics
Java Server Faces (JSF) - BasicsJava Server Faces (JSF) - Basics
Java Server Faces (JSF) - Basics
 
JSTL
JSTLJSTL
JSTL
 
Unified Expression Language
Unified Expression LanguageUnified Expression Language
Unified Expression Language
 
Java Server Pages
Java Server PagesJava Server Pages
Java Server Pages
 
Web Applications and Deployment
Web Applications and DeploymentWeb Applications and Deployment
Web Applications and Deployment
 
Java Servlets
Java ServletsJava Servlets
Java Servlets
 
CSS
CSSCSS
CSS
 
HTML: Tables and Forms
HTML: Tables and FormsHTML: Tables and Forms
HTML: Tables and Forms
 
HTML Fundamentals
HTML FundamentalsHTML Fundamentals
HTML Fundamentals
 
WWW and HTTP
WWW and HTTPWWW and HTTP
WWW and HTTP
 
JavaScript and jQuery Fundamentals
JavaScript and jQuery FundamentalsJavaScript and jQuery Fundamentals
JavaScript and jQuery Fundamentals
 
Creating Web Sites with HTML and CSS
Creating Web Sites with HTML and CSSCreating Web Sites with HTML and CSS
Creating Web Sites with HTML and CSS
 
Processing XML with Java
Processing XML with JavaProcessing XML with Java
Processing XML with Java
 
Introduction to XML
Introduction to XMLIntroduction to XML
Introduction to XML
 
Data Access with JDBC
Data Access with JDBCData Access with JDBC
Data Access with JDBC
 
Introduction to-sql
Introduction to-sqlIntroduction to-sql
Introduction to-sql
 
Introduction to-RDBMS-systems
Introduction to-RDBMS-systemsIntroduction to-RDBMS-systems
Introduction to-RDBMS-systems
 

Último

What Life Would Be Like From A Different Perspective (saltyvixenstories.com)
What Life Would Be Like From A Different Perspective (saltyvixenstories.com)What Life Would Be Like From A Different Perspective (saltyvixenstories.com)
What Life Would Be Like From A Different Perspective (saltyvixenstories.com)Salty Vixen Stories & More
 
Transform Your Space with Poster Memorabilia's Collection
Transform Your Space with Poster Memorabilia's CollectionTransform Your Space with Poster Memorabilia's Collection
Transform Your Space with Poster Memorabilia's CollectionPoster Memorabilia Reviews
 
A Spotlight on Darla Leigh Pittman Rodgers: Aaron Rodgers' Mother
A Spotlight on Darla Leigh Pittman Rodgers: Aaron Rodgers' MotherA Spotlight on Darla Leigh Pittman Rodgers: Aaron Rodgers' Mother
A Spotlight on Darla Leigh Pittman Rodgers: Aaron Rodgers' Motherget joys
 
Dubai Call Girls O525547819 Face Full Beautiful Call Girls Dubai
Dubai Call Girls O525547819 Face Full Beautiful Call Girls DubaiDubai Call Girls O525547819 Face Full Beautiful Call Girls Dubai
Dubai Call Girls O525547819 Face Full Beautiful Call Girls Dubaikojalkojal131
 
Bald Philosopher, a story for entertainment.docx
Bald Philosopher, a story for entertainment.docxBald Philosopher, a story for entertainment.docx
Bald Philosopher, a story for entertainment.docxazuremorn
 
Mince Pies, a story for entertainment.docx
Mince Pies, a story for entertainment.docxMince Pies, a story for entertainment.docx
Mince Pies, a story for entertainment.docxazuremorn
 
Flying Avocado Cat Cryptocurrency Created, Coded, Generated and Named by Grok...
Flying Avocado Cat Cryptocurrency Created, Coded, Generated and Named by Grok...Flying Avocado Cat Cryptocurrency Created, Coded, Generated and Named by Grok...
Flying Avocado Cat Cryptocurrency Created, Coded, Generated and Named by Grok...TeslaStakeHolder
 
Cabin by the azure lake, the story of a lady and a crocodile
Cabin by the azure lake, the story of a lady and a crocodileCabin by the azure lake, the story of a lady and a crocodile
Cabin by the azure lake, the story of a lady and a crocodileazuremorn
 
Fight Scene Storyboard (Action/Adventure Animation)
Fight Scene Storyboard (Action/Adventure Animation)Fight Scene Storyboard (Action/Adventure Animation)
Fight Scene Storyboard (Action/Adventure Animation)finlaygoodall2
 
Uk-NO1 Amil In Karachi Best Amil In Karachi Bangali Baba In Karachi Aamil In ...
Uk-NO1 Amil In Karachi Best Amil In Karachi Bangali Baba In Karachi Aamil In ...Uk-NO1 Amil In Karachi Best Amil In Karachi Bangali Baba In Karachi Aamil In ...
Uk-NO1 Amil In Karachi Best Amil In Karachi Bangali Baba In Karachi Aamil In ...Amil baba
 
The Old Man and the Earthquake, a story for entertainment
The Old Man and the Earthquake, a story for entertainmentThe Old Man and the Earthquake, a story for entertainment
The Old Man and the Earthquake, a story for entertainmentazuremorn
 
THE MEDIC, A STORY for entertainment.docx
THE MEDIC, A STORY for entertainment.docxTHE MEDIC, A STORY for entertainment.docx
THE MEDIC, A STORY for entertainment.docxazuremorn
 
karaoke songs customise for portable 2.docx
karaoke songs customise for portable  2.docxkaraoke songs customise for portable  2.docx
karaoke songs customise for portable 2.docxPOPCOMTABUKCITY
 
Biswanath Byam Samiti Open Quiz 2022 by Qui9 Grand Finale
Biswanath Byam Samiti Open Quiz 2022 by Qui9 Grand FinaleBiswanath Byam Samiti Open Quiz 2022 by Qui9 Grand Finale
Biswanath Byam Samiti Open Quiz 2022 by Qui9 Grand FinaleQui9 (Ultimate Quizzing)
 
ECOLUXE pre-ESPYS Ultimate Sports Lounge 2024
ECOLUXE pre-ESPYS Ultimate Sports Lounge 2024ECOLUXE pre-ESPYS Ultimate Sports Lounge 2024
ECOLUXE pre-ESPYS Ultimate Sports Lounge 2024Durkin Entertainment LLC
 
TREE VOLANOES, A STORY FOR ENTERTAINMENT
TREE VOLANOES, A STORY FOR ENTERTAINMENTTREE VOLANOES, A STORY FOR ENTERTAINMENT
TREE VOLANOES, A STORY FOR ENTERTAINMENTazuremorn
 

Último (20)

What Life Would Be Like From A Different Perspective (saltyvixenstories.com)
What Life Would Be Like From A Different Perspective (saltyvixenstories.com)What Life Would Be Like From A Different Perspective (saltyvixenstories.com)
What Life Would Be Like From A Different Perspective (saltyvixenstories.com)
 
Transform Your Space with Poster Memorabilia's Collection
Transform Your Space with Poster Memorabilia's CollectionTransform Your Space with Poster Memorabilia's Collection
Transform Your Space with Poster Memorabilia's Collection
 
A Spotlight on Darla Leigh Pittman Rodgers: Aaron Rodgers' Mother
A Spotlight on Darla Leigh Pittman Rodgers: Aaron Rodgers' MotherA Spotlight on Darla Leigh Pittman Rodgers: Aaron Rodgers' Mother
A Spotlight on Darla Leigh Pittman Rodgers: Aaron Rodgers' Mother
 
S10_E02_How to Pimp Social Media 101.pptx
S10_E02_How to Pimp Social Media 101.pptxS10_E02_How to Pimp Social Media 101.pptx
S10_E02_How to Pimp Social Media 101.pptx
 
Dubai Call Girls O525547819 Face Full Beautiful Call Girls Dubai
Dubai Call Girls O525547819 Face Full Beautiful Call Girls DubaiDubai Call Girls O525547819 Face Full Beautiful Call Girls Dubai
Dubai Call Girls O525547819 Face Full Beautiful Call Girls Dubai
 
Sincerely, The Friday Club - Farewell Quiz-Finals.pptx
Sincerely, The Friday Club - Farewell Quiz-Finals.pptxSincerely, The Friday Club - Farewell Quiz-Finals.pptx
Sincerely, The Friday Club - Farewell Quiz-Finals.pptx
 
Bald Philosopher, a story for entertainment.docx
Bald Philosopher, a story for entertainment.docxBald Philosopher, a story for entertainment.docx
Bald Philosopher, a story for entertainment.docx
 
Moveable Feast_Travel-Lifestyle-Culture Quiz.pptx
Moveable Feast_Travel-Lifestyle-Culture Quiz.pptxMoveable Feast_Travel-Lifestyle-Culture Quiz.pptx
Moveable Feast_Travel-Lifestyle-Culture Quiz.pptx
 
Mince Pies, a story for entertainment.docx
Mince Pies, a story for entertainment.docxMince Pies, a story for entertainment.docx
Mince Pies, a story for entertainment.docx
 
Flying Avocado Cat Cryptocurrency Created, Coded, Generated and Named by Grok...
Flying Avocado Cat Cryptocurrency Created, Coded, Generated and Named by Grok...Flying Avocado Cat Cryptocurrency Created, Coded, Generated and Named by Grok...
Flying Avocado Cat Cryptocurrency Created, Coded, Generated and Named by Grok...
 
S10_E06-Sincerely,The Friday Club- Prelims Farewell Quiz.pptx
S10_E06-Sincerely,The Friday Club- Prelims Farewell Quiz.pptxS10_E06-Sincerely,The Friday Club- Prelims Farewell Quiz.pptx
S10_E06-Sincerely,The Friday Club- Prelims Farewell Quiz.pptx
 
Cabin by the azure lake, the story of a lady and a crocodile
Cabin by the azure lake, the story of a lady and a crocodileCabin by the azure lake, the story of a lady and a crocodile
Cabin by the azure lake, the story of a lady and a crocodile
 
Fight Scene Storyboard (Action/Adventure Animation)
Fight Scene Storyboard (Action/Adventure Animation)Fight Scene Storyboard (Action/Adventure Animation)
Fight Scene Storyboard (Action/Adventure Animation)
 
Uk-NO1 Amil In Karachi Best Amil In Karachi Bangali Baba In Karachi Aamil In ...
Uk-NO1 Amil In Karachi Best Amil In Karachi Bangali Baba In Karachi Aamil In ...Uk-NO1 Amil In Karachi Best Amil In Karachi Bangali Baba In Karachi Aamil In ...
Uk-NO1 Amil In Karachi Best Amil In Karachi Bangali Baba In Karachi Aamil In ...
 
The Old Man and the Earthquake, a story for entertainment
The Old Man and the Earthquake, a story for entertainmentThe Old Man and the Earthquake, a story for entertainment
The Old Man and the Earthquake, a story for entertainment
 
THE MEDIC, A STORY for entertainment.docx
THE MEDIC, A STORY for entertainment.docxTHE MEDIC, A STORY for entertainment.docx
THE MEDIC, A STORY for entertainment.docx
 
karaoke songs customise for portable 2.docx
karaoke songs customise for portable  2.docxkaraoke songs customise for portable  2.docx
karaoke songs customise for portable 2.docx
 
Biswanath Byam Samiti Open Quiz 2022 by Qui9 Grand Finale
Biswanath Byam Samiti Open Quiz 2022 by Qui9 Grand FinaleBiswanath Byam Samiti Open Quiz 2022 by Qui9 Grand Finale
Biswanath Byam Samiti Open Quiz 2022 by Qui9 Grand Finale
 
ECOLUXE pre-ESPYS Ultimate Sports Lounge 2024
ECOLUXE pre-ESPYS Ultimate Sports Lounge 2024ECOLUXE pre-ESPYS Ultimate Sports Lounge 2024
ECOLUXE pre-ESPYS Ultimate Sports Lounge 2024
 
TREE VOLANOES, A STORY FOR ENTERTAINMENT
TREE VOLANOES, A STORY FOR ENTERTAINMENTTREE VOLANOES, A STORY FOR ENTERTAINMENT
TREE VOLANOES, A STORY FOR ENTERTAINMENT
 

Strings v.1.1

  • 1. Strings and Strings Manipulation
  • 2.
  • 3.
  • 5.
  • 6.
  • 7.
  • 8. Strings – First Example String s = &quot;Stand up, stand up, Balkan superman.&quot;; System.out.printf(&quot;s = amp;quot;%samp;quot;%n&quot;, s); System.out.printf(&quot;s. l ength () = %d%n&quot;, s.length()); for (int i = 0; i < s.length(); i++) { System.out.printf(&quot;s[%d] = %c%n&quot;, i, s.charAt(i)); }
  • 9. Strings – First Example Live Demo
  • 10. Declaring, Creating, Reading and Printing Creating and Using Strings
  • 11.
  • 12.
  • 13.
  • 14.
  • 15. Live Demo Reading and Printing Strings
  • 16. Manipulating Strings Comparing, Concatenating, Searching, Extracting Substrings, Splitting
  • 17.
  • 18.
  • 19.
  • 20.
  • 22.
  • 23. Concatenating Strings – Example String firstName = &quot;Svetlin&quot;; String lastName = &quot;Nakov&quot;; String fullName = firstName + &quot; &quot; + lastName; System.out.println(fullName); int age = 2 6 ; String nameAndAge = &quot;Name: &quot; + fullName + &quot;Age: &quot; + age; System.out.println(nameAndAge); // Name: Svetlin Nakov // Age: 2 6
  • 25.
  • 26. Searching Strings – Example String str = &quot;Java Programming Course&quot;; int index = str.indexOf(&quot;Java&quot;); // index = 0 index = str.indexOf(&quot;Course&quot;); // index = 17 index = str.indexOf(&quot;COURSE&quot;); // index = -1 // indexOf is case sensetive. -1 means not found index = str.indexOf(&quot;ram&quot;); // index = 9 index = str.indexOf(&quot;r&quot;); // index = 6 index = str.indexOf(&quot;r&quot;, 7); // index = 9 index = str.indexOf(&quot;r&quot;, 10); // index = 20 i = s.charAt(i) = 0 1 2 3 4 5 6 7 8 9 10 11 12 … J a v a P r o g r a m m …
  • 28.
  • 30.
  • 31. Splitting Strings - Example String listOfBeers = &quot;Amstel, Zagorka, Tuborg, Becks.&quot;; String[] beers = listOfBeers.split(&quot;[ ,.]&quot;); System.out.println(&quot;Available beers are:&quot;); for (String beer : beers) { if (!&quot;&quot;.equalsIgnoreCase(beer)) { System.out.println(beer); } }
  • 33. Other String Operations Replacing Substrings, Changing Character Casing, Trimming
  • 34.
  • 35.
  • 36.
  • 38. Building and Modifying Strings Using StringBuilder C lass
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46. Using StringBuilder Live Demo
  • 47. Formatting Strings Using t oString() and String. f ormat()
  • 48.
  • 49.
  • 50.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.
  • 61.
  • 62.

Notas del editor

  1. * 12/04/10 07/16/96 (c) 2005 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  2. * 12/04/10 07/16/96 (c) 2005 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  3. * 12/04/10 07/16/96 (c) 2005 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  4. * 12/04/10 07/16/96 (c) 2005 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  5. * 12/04/10 07/16/96 (c) 2005 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  6. * 12/04/10 07/16/96 (c) 2005 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  7. * 12/04/10 07/16/96 (c) 2005 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  8. * 12/04/10 07/16/96 (c) 2005 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  9. * 12/04/10 07/16/96 (c) 2005 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  10. * 12/04/10 07/16/96 (c) 2005 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  11. * 12/04/10 07/16/96 (c) 2005 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  12. * 12/04/10 07/16/96 (c) 2005 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  13. * 12/04/10 07/16/96 (c) 2005 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  14. * 12/04/10 07/16/96 (c) 2005 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  15. * 12/04/10 07/16/96 (c) 2005 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  16. * 12/04/10 07/16/96 (c) 2005 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ## Introducing the StringBuffer Class StringBuffer represents strings that can be modified and extended at run time. The following example creates three new String objects, and copies all the characters each time a new String is created: String quote = &amp;quot;Fasten your seatbelts, &amp;quot;; quote = quote + &amp;quot;it’s going to be a bumpy night.&amp;quot;; It is more efficient to preallocate the amount of space required using the StringBuffer constructor, and its append() method as follows: StringBuffer quote = new StringBuffer(60); // alloc 60 chars quote.append(&amp;quot;Fasten your seatbelts, &amp;quot;); quote.append(&amp;quot; it’s going to be a bumpy night. &amp;quot;); StringBuffer also provides a number of overloaded insert() methods for inserting various types of data at a particular location in the string buffer. Instructor Note The example in the slide uses StringBuffer to reverse the characters in a string. A StringBuffer object is created, with the same length as the string. The loop traverses the String parameter in reverse order and appends each of its characters to the StringBuffer object by using append() . The StringBuffer therefore holds a reverse copy of the String parameter. At the end of the method, a new String object is created from the StringBuffer object, and this String is returned from the method .
  17. * 12/04/10 07/16/96 (c) 2005 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  18. * 12/04/10 07/16/96 (c) 2005 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  19. * 12/04/10 07/16/96 (c) 2005 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  20. * 12/04/10 07/16/96 (c) 2005 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  21. * 12/04/10 07/16/96 (c) 2005 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  22. * 12/04/10 07/16/96 (c) 2005 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  23. * 12/04/10 07/16/96 (c) 2005 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  24. * 12/04/10 07/16/96 (c) 2005 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##