SlideShare ist ein Scribd-Unternehmen logo
1 von 62
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]

Weitere ähnliche Inhalte

Was ist angesagt?

String and string buffer
String and string bufferString and string buffer
String and string buffer
kamal kotecha
 
Understanding java streams
Understanding java streamsUnderstanding java streams
Understanding java streams
Shahjahan Samoon
 

Was ist angesagt? (20)

String and string buffer
String and string bufferString and string buffer
String and string buffer
 
Exception handling
Exception handlingException handling
Exception handling
 
Regular Expressions in Java
Regular Expressions in JavaRegular Expressions in Java
Regular Expressions in Java
 
Java exception
Java exception Java exception
Java exception
 
Strings in Java
Strings in JavaStrings in Java
Strings in Java
 
Java I/o streams
Java I/o streamsJava I/o streams
Java I/o streams
 
Method overriding
Method overridingMethod overriding
Method overriding
 
Java applet - java
Java applet - javaJava applet - java
Java applet - java
 
Understanding java streams
Understanding java streamsUnderstanding java streams
Understanding java streams
 
Operators in java
Operators in javaOperators in java
Operators in java
 
Control statements in java programmng
Control statements in java programmngControl statements in java programmng
Control statements in java programmng
 
enums
enumsenums
enums
 
Exception handling
Exception handlingException handling
Exception handling
 
Java Networking
Java NetworkingJava Networking
Java Networking
 
ArrayList in JAVA
ArrayList in JAVAArrayList in JAVA
ArrayList in JAVA
 
Regular expressions in Python
Regular expressions in PythonRegular expressions in Python
Regular expressions in Python
 
Python variables and data types.pptx
Python variables and data types.pptxPython variables and data types.pptx
Python variables and data types.pptx
 
Java String Handling
Java String HandlingJava String Handling
Java String Handling
 
Java interfaces
Java   interfacesJava   interfaces
Java interfaces
 
Control flow statements in java
Control flow statements in javaControl flow statements in java
Control flow statements in java
 

Andere mochten auch (11)

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
 
Introduction to Java Strings, By Kavita Ganesan
Introduction to Java Strings, By Kavita GanesanIntroduction to Java Strings, By Kavita Ganesan
Introduction to Java Strings, By Kavita Ganesan
 
Java servlet life cycle - methods ppt
Java servlet life cycle - methods pptJava servlet life cycle - methods ppt
Java servlet life cycle - methods ppt
 

Ähnlich wie Strings v.1.1

String and string manipulation x
String and string manipulation xString and string manipulation x
String and string manipulation x
Shahjahan Samoon
 
String and string manipulation
String and string manipulationString and string manipulation
String and string manipulation
Shahjahan Samoon
 
Java căn bản - Chapter9
Java căn bản - Chapter9Java căn bản - Chapter9
Java căn bản - Chapter9
Vince 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-phpapp02
Abdul Samee
 
Regular Expression
Regular ExpressionRegular Expression
Regular Expression
Bharat17485
 

Ähnlich wie 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
 
Handling of character strings C programming
Handling of character strings C programmingHandling of character strings C programming
Handling of character strings C programming
 
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
 

Mehr von BG Java EE Course

Java Server Faces (JSF) - advanced
Java Server Faces (JSF) - advancedJava Server Faces (JSF) - advanced
Java Server Faces (JSF) - advanced
BG Java EE Course
 
JavaScript and jQuery Fundamentals
JavaScript and jQuery FundamentalsJavaScript and jQuery Fundamentals
JavaScript and jQuery Fundamentals
BG Java EE Course
 
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
BG Java EE Course
 

Mehr von 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
 

Kürzlich hochgeladen

Models in Deira 0567006274 Deira Call girl Service
Models in Deira 0567006274 Deira Call girl ServiceModels in Deira 0567006274 Deira Call girl Service
Models in Deira 0567006274 Deira Call girl Service
Monica Sydney
 
Dubai Call girls Service 0524076003 Call girls services in Dubai
Dubai Call girls Service 0524076003 Call girls services in DubaiDubai Call girls Service 0524076003 Call girls services in Dubai
Dubai Call girls Service 0524076003 Call girls services in Dubai
Monica Sydney
 
Dubai Call girls Service 0524076003 Call girls in Dubai
Dubai Call girls Service 0524076003 Call girls in DubaiDubai Call girls Service 0524076003 Call girls in Dubai
Dubai Call girls Service 0524076003 Call girls in Dubai
Monica Sydney
 

Kürzlich hochgeladen (20)

Call girls Service in Deira 0507330913 Deira Call girls
Call girls Service in Deira 0507330913 Deira Call girlsCall girls Service in Deira 0507330913 Deira Call girls
Call girls Service in Deira 0507330913 Deira Call girls
 
Call girls Service Berhampur - 9332606886 Our call girls are sure to provide ...
Call girls Service Berhampur - 9332606886 Our call girls are sure to provide ...Call girls Service Berhampur - 9332606886 Our call girls are sure to provide ...
Call girls Service Berhampur - 9332606886 Our call girls are sure to provide ...
 
Genuine 8617370543 Hot and Beautiful 💕 Gomati Escorts call Girls
Genuine 8617370543 Hot and Beautiful 💕 Gomati Escorts call GirlsGenuine 8617370543 Hot and Beautiful 💕 Gomati Escorts call Girls
Genuine 8617370543 Hot and Beautiful 💕 Gomati Escorts call Girls
 
Call Girls Bijnor Just Call 8617370543 Top Class Call Girl Service Available
Call Girls Bijnor  Just Call 8617370543 Top Class Call Girl Service AvailableCall Girls Bijnor  Just Call 8617370543 Top Class Call Girl Service Available
Call Girls Bijnor Just Call 8617370543 Top Class Call Girl Service Available
 
Call Girls Bhubaneswar 9777949614 call me Independent Escort Service Bhubaneswar
Call Girls Bhubaneswar 9777949614 call me Independent Escort Service BhubaneswarCall Girls Bhubaneswar 9777949614 call me Independent Escort Service Bhubaneswar
Call Girls Bhubaneswar 9777949614 call me Independent Escort Service Bhubaneswar
 
Banda call girls 📞 8617370543At Low Cost Cash Payment Booking
Banda call girls 📞 8617370543At Low Cost Cash Payment BookingBanda call girls 📞 8617370543At Low Cost Cash Payment Booking
Banda call girls 📞 8617370543At Low Cost Cash Payment Booking
 
Deira call girls 0507330913 Call girls in Deira
Deira call girls 0507330913  Call girls in DeiraDeira call girls 0507330913  Call girls in Deira
Deira call girls 0507330913 Call girls in Deira
 
Satara call girl 8617370543♥️ call girls in satara escort service
Satara call girl 8617370543♥️ call girls in satara escort serviceSatara call girl 8617370543♥️ call girls in satara escort service
Satara call girl 8617370543♥️ call girls in satara escort service
 
Models in Deira 0567006274 Deira Call girl Service
Models in Deira 0567006274 Deira Call girl ServiceModels in Deira 0567006274 Deira Call girl Service
Models in Deira 0567006274 Deira Call girl Service
 
Call Girls In Amreli Escorts ☎️8617370543 🔝 💃 Enjoy 24/7 Escort Service Enjoy...
Call Girls In Amreli Escorts ☎️8617370543 🔝 💃 Enjoy 24/7 Escort Service Enjoy...Call Girls In Amreli Escorts ☎️8617370543 🔝 💃 Enjoy 24/7 Escort Service Enjoy...
Call Girls In Amreli Escorts ☎️8617370543 🔝 💃 Enjoy 24/7 Escort Service Enjoy...
 
Call Girls In Gorakhpur Escorts ☎️8617370543 🔝 💃 Enjoy 24/7 Escort Service En...
Call Girls In Gorakhpur Escorts ☎️8617370543 🔝 💃 Enjoy 24/7 Escort Service En...Call Girls In Gorakhpur Escorts ☎️8617370543 🔝 💃 Enjoy 24/7 Escort Service En...
Call Girls In Gorakhpur Escorts ☎️8617370543 🔝 💃 Enjoy 24/7 Escort Service En...
 
Call Girls in Perumbavoor / 9332606886 Genuine Call girls with real Photos an...
Call Girls in Perumbavoor / 9332606886 Genuine Call girls with real Photos an...Call Girls in Perumbavoor / 9332606886 Genuine Call girls with real Photos an...
Call Girls in Perumbavoor / 9332606886 Genuine Call girls with real Photos an...
 
Call Girls in Kollam - 9332606886 Our call girls are sure to provide you with...
Call Girls in Kollam - 9332606886 Our call girls are sure to provide you with...Call Girls in Kollam - 9332606886 Our call girls are sure to provide you with...
Call Girls in Kollam - 9332606886 Our call girls are sure to provide you with...
 
Top IPTV Subscription Service to Stream Your Favorite Shows in 2024.pdf
Top IPTV Subscription Service to Stream Your Favorite Shows in 2024.pdfTop IPTV Subscription Service to Stream Your Favorite Shows in 2024.pdf
Top IPTV Subscription Service to Stream Your Favorite Shows in 2024.pdf
 
Bhubaneswar🌹Patia ❤CALL GIRLS 9777949614 💟 CALL GIRLS IN bhubaneswar ESCORT S...
Bhubaneswar🌹Patia ❤CALL GIRLS 9777949614 💟 CALL GIRLS IN bhubaneswar ESCORT S...Bhubaneswar🌹Patia ❤CALL GIRLS 9777949614 💟 CALL GIRLS IN bhubaneswar ESCORT S...
Bhubaneswar🌹Patia ❤CALL GIRLS 9777949614 💟 CALL GIRLS IN bhubaneswar ESCORT S...
 
Dubai Call girls Service 0524076003 Call girls services in Dubai
Dubai Call girls Service 0524076003 Call girls services in DubaiDubai Call girls Service 0524076003 Call girls services in Dubai
Dubai Call girls Service 0524076003 Call girls services in Dubai
 
Dubai Call girls Service 0524076003 Call girls in Dubai
Dubai Call girls Service 0524076003 Call girls in DubaiDubai Call girls Service 0524076003 Call girls in Dubai
Dubai Call girls Service 0524076003 Call girls in Dubai
 
Vip Call Girls Bhubaneswar 🐱‍🏍 9777949614 Independent Escorts Service Bhubane...
Vip Call Girls Bhubaneswar 🐱‍🏍 9777949614 Independent Escorts Service Bhubane...Vip Call Girls Bhubaneswar 🐱‍🏍 9777949614 Independent Escorts Service Bhubane...
Vip Call Girls Bhubaneswar 🐱‍🏍 9777949614 Independent Escorts Service Bhubane...
 
Hire 💕 8617370543 Mirzapur Call Girls Service Call Girls Agency
Hire 💕 8617370543 Mirzapur Call Girls Service Call Girls AgencyHire 💕 8617370543 Mirzapur Call Girls Service Call Girls Agency
Hire 💕 8617370543 Mirzapur Call Girls Service Call Girls Agency
 
🌹Bhubaneswar🌹Ravi Tailkes ❤CALL GIRL 9777949614 ❤CALL GIRLS IN bhubaneswar E...
🌹Bhubaneswar🌹Ravi Tailkes  ❤CALL GIRL 9777949614 ❤CALL GIRLS IN bhubaneswar E...🌹Bhubaneswar🌹Ravi Tailkes  ❤CALL GIRL 9777949614 ❤CALL GIRLS IN bhubaneswar E...
🌹Bhubaneswar🌹Ravi Tailkes ❤CALL GIRL 9777949614 ❤CALL GIRLS IN bhubaneswar E...
 

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.

Hinweis der Redaktion

  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.* ##