SlideShare uma empresa Scribd logo
1 de 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]

Mais conteúdo relacionado

Mais procurados

Mais procurados (20)

Exception handling
Exception handlingException handling
Exception handling
 
JVM Memory Management Details
JVM Memory Management DetailsJVM Memory Management Details
JVM Memory Management Details
 
L14 exception handling
L14 exception handlingL14 exception handling
L14 exception handling
 
Java - File Input Output Concepts
Java - File Input Output ConceptsJava - File Input Output Concepts
Java - File Input Output Concepts
 
Java Serialization
Java SerializationJava Serialization
Java Serialization
 
Features of java
Features of javaFeatures of java
Features of java
 
Java Collections
Java  Collections Java  Collections
Java Collections
 
CSS Unit I - Basics of JavaScript Programming
CSS Unit I - Basics of JavaScript ProgrammingCSS Unit I - Basics of JavaScript Programming
CSS Unit I - Basics of JavaScript Programming
 
String, string builder, string buffer
String, string builder, string bufferString, string builder, string buffer
String, string builder, string buffer
 
Input processing and output in Python
Input processing and output in PythonInput processing and output in Python
Input processing and output in Python
 
Regular Expressions in Java
Regular Expressions in JavaRegular Expressions in Java
Regular Expressions in Java
 
Java Arrays
Java ArraysJava Arrays
Java Arrays
 
Task parallel library presentation
Task parallel library presentationTask parallel library presentation
Task parallel library presentation
 
Semaphore
Semaphore Semaphore
Semaphore
 
Linux shell env
Linux shell envLinux shell env
Linux shell env
 
Exception Handling
Exception HandlingException Handling
Exception Handling
 
14 file handling
14 file handling14 file handling
14 file handling
 
BANKER'S ALGORITHM
BANKER'S ALGORITHMBANKER'S ALGORITHM
BANKER'S ALGORITHM
 
Event handling
Event handlingEvent handling
Event handling
 
Dynamic memory allocation in c
Dynamic memory allocation in cDynamic memory allocation in c
Dynamic memory allocation in c
 

Destaque (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
 

Semelhante 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
 
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
 
Strings in Python
Strings in PythonStrings in Python
Strings in Pythonnitamhaske
 

Semelhante 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
 
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
 

Mais 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

❤Personal Whatsapp Number Mukteshwar Call Girls 8617697112 💦✅.
❤Personal Whatsapp Number Mukteshwar Call Girls 8617697112 💦✅.❤Personal Whatsapp Number Mukteshwar Call Girls 8617697112 💦✅.
❤Personal Whatsapp Number Mukteshwar Call Girls 8617697112 💦✅.Nitya salvi
 
Hire 💕 8617697112 North Sikkim Call Girls Service Call Girls Agency
Hire 💕 8617697112 North Sikkim Call Girls Service Call Girls AgencyHire 💕 8617697112 North Sikkim Call Girls Service Call Girls Agency
Hire 💕 8617697112 North Sikkim Call Girls Service Call Girls AgencyNitya salvi
 
𓀤Call On 6297143586 𓀤 Park Street Call Girls In All Kolkata 24/7 Provide Call...
𓀤Call On 6297143586 𓀤 Park Street Call Girls In All Kolkata 24/7 Provide Call...𓀤Call On 6297143586 𓀤 Park Street Call Girls In All Kolkata 24/7 Provide Call...
𓀤Call On 6297143586 𓀤 Park Street Call Girls In All Kolkata 24/7 Provide Call...rahim quresi
 
Kanpur call girls 📞 8617697112 At Low Cost Cash Payment Booking
Kanpur call girls 📞 8617697112 At Low Cost Cash Payment BookingKanpur call girls 📞 8617697112 At Low Cost Cash Payment Booking
Kanpur call girls 📞 8617697112 At Low Cost Cash Payment BookingNitya salvi
 
Sonagachi ( Call Girls ) Kolkata ✔ 6297143586 ✔ Hot Model With Sexy Bhabi Rea...
Sonagachi ( Call Girls ) Kolkata ✔ 6297143586 ✔ Hot Model With Sexy Bhabi Rea...Sonagachi ( Call Girls ) Kolkata ✔ 6297143586 ✔ Hot Model With Sexy Bhabi Rea...
Sonagachi ( Call Girls ) Kolkata ✔ 6297143586 ✔ Hot Model With Sexy Bhabi Rea...rahim quresi
 
Dum Dum ( Call Girls ) Kolkata ✔ 6297143586 ✔ Hot Model With Sexy Bhabi Ready...
Dum Dum ( Call Girls ) Kolkata ✔ 6297143586 ✔ Hot Model With Sexy Bhabi Ready...Dum Dum ( Call Girls ) Kolkata ✔ 6297143586 ✔ Hot Model With Sexy Bhabi Ready...
Dum Dum ( Call Girls ) Kolkata ✔ 6297143586 ✔ Hot Model With Sexy Bhabi Ready...ritikasharma
 
Navsari Escorts Service ☎️ 6378878445 ( Sakshi Sinha ) High Profile Call Girl...
Navsari Escorts Service ☎️ 6378878445 ( Sakshi Sinha ) High Profile Call Girl...Navsari Escorts Service ☎️ 6378878445 ( Sakshi Sinha ) High Profile Call Girl...
Navsari Escorts Service ☎️ 6378878445 ( Sakshi Sinha ) High Profile Call Girl...mriyagarg453
 
📞 Contact Number 8617697112 VIP Ganderbal Call Girls
📞 Contact Number 8617697112 VIP Ganderbal Call Girls📞 Contact Number 8617697112 VIP Ganderbal Call Girls
📞 Contact Number 8617697112 VIP Ganderbal Call GirlsNitya salvi
 
Verified Trusted Call Girls Tambaram Chennai ✔✔7427069034 Independent Chenna...
Verified Trusted Call Girls Tambaram Chennai ✔✔7427069034  Independent Chenna...Verified Trusted Call Girls Tambaram Chennai ✔✔7427069034  Independent Chenna...
Verified Trusted Call Girls Tambaram Chennai ✔✔7427069034 Independent Chenna... Shivani Pandey
 
(TOP CLASS) Call Girls In Nungambakkam Phone 7427069034 Call Girls Model With...
(TOP CLASS) Call Girls In Nungambakkam Phone 7427069034 Call Girls Model With...(TOP CLASS) Call Girls In Nungambakkam Phone 7427069034 Call Girls Model With...
(TOP CLASS) Call Girls In Nungambakkam Phone 7427069034 Call Girls Model With... Shivani Pandey
 
Hotel And Home Service Available Kolkata Call Girls Park Street ✔ 6297143586 ...
Hotel And Home Service Available Kolkata Call Girls Park Street ✔ 6297143586 ...Hotel And Home Service Available Kolkata Call Girls Park Street ✔ 6297143586 ...
Hotel And Home Service Available Kolkata Call Girls Park Street ✔ 6297143586 ...ritikasharma
 
❤Personal Whatsapp Number Keylong Call Girls 8617697112 💦✅.
❤Personal Whatsapp Number Keylong Call Girls 8617697112 💦✅.❤Personal Whatsapp Number Keylong Call Girls 8617697112 💦✅.
❤Personal Whatsapp Number Keylong Call Girls 8617697112 💦✅.Nitya salvi
 
Zirakpur Call Girls👧 Book Now📱8146719683 📞👉Mohali Call Girl Service No Advanc...
Zirakpur Call Girls👧 Book Now📱8146719683 📞👉Mohali Call Girl Service No Advanc...Zirakpur Call Girls👧 Book Now📱8146719683 📞👉Mohali Call Girl Service No Advanc...
Zirakpur Call Girls👧 Book Now📱8146719683 📞👉Mohali Call Girl Service No Advanc...rajveermohali2022
 
Top Rated Pune Call Girls Dhayari ⟟ 6297143586 ⟟ Call Me For Genuine Sex Ser...
Top Rated  Pune Call Girls Dhayari ⟟ 6297143586 ⟟ Call Me For Genuine Sex Ser...Top Rated  Pune Call Girls Dhayari ⟟ 6297143586 ⟟ Call Me For Genuine Sex Ser...
Top Rated Pune Call Girls Dhayari ⟟ 6297143586 ⟟ Call Me For Genuine Sex Ser...Call Girls in Nagpur High Profile
 
VIP Model Call Girls Koregaon Park ( Pune ) Call ON 8005736733 Starting From ...
VIP Model Call Girls Koregaon Park ( Pune ) Call ON 8005736733 Starting From ...VIP Model Call Girls Koregaon Park ( Pune ) Call ON 8005736733 Starting From ...
VIP Model Call Girls Koregaon Park ( Pune ) Call ON 8005736733 Starting From ...SUHANI PANDEY
 
Beautiful 😋 Call girls in Lahore 03210033448
Beautiful 😋 Call girls in Lahore 03210033448Beautiful 😋 Call girls in Lahore 03210033448
Beautiful 😋 Call girls in Lahore 03210033448ont65320
 
Top Rated Kolkata Call Girls Dum Dum ⟟ 6297143586 ⟟ Call Me For Genuine Sex S...
Top Rated Kolkata Call Girls Dum Dum ⟟ 6297143586 ⟟ Call Me For Genuine Sex S...Top Rated Kolkata Call Girls Dum Dum ⟟ 6297143586 ⟟ Call Me For Genuine Sex S...
Top Rated Kolkata Call Girls Dum Dum ⟟ 6297143586 ⟟ Call Me For Genuine Sex S...ritikasharma
 
Top Rated Kolkata Call Girls Khardah ⟟ 6297143586 ⟟ Call Me For Genuine Sex S...
Top Rated Kolkata Call Girls Khardah ⟟ 6297143586 ⟟ Call Me For Genuine Sex S...Top Rated Kolkata Call Girls Khardah ⟟ 6297143586 ⟟ Call Me For Genuine Sex S...
Top Rated Kolkata Call Girls Khardah ⟟ 6297143586 ⟟ Call Me For Genuine Sex S...ritikasharma
 
Call Girls Manjri Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Manjri Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Manjri Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Manjri Call Me 7737669865 Budget Friendly No Advance Bookingroncy bisnoi
 
Verified Trusted Call Girls Ambattur Chennai ✔✔7427069034 Independent Chenna...
Verified Trusted Call Girls Ambattur Chennai ✔✔7427069034  Independent Chenna...Verified Trusted Call Girls Ambattur Chennai ✔✔7427069034  Independent Chenna...
Verified Trusted Call Girls Ambattur Chennai ✔✔7427069034 Independent Chenna... Shivani Pandey
 

Último (20)

❤Personal Whatsapp Number Mukteshwar Call Girls 8617697112 💦✅.
❤Personal Whatsapp Number Mukteshwar Call Girls 8617697112 💦✅.❤Personal Whatsapp Number Mukteshwar Call Girls 8617697112 💦✅.
❤Personal Whatsapp Number Mukteshwar Call Girls 8617697112 💦✅.
 
Hire 💕 8617697112 North Sikkim Call Girls Service Call Girls Agency
Hire 💕 8617697112 North Sikkim Call Girls Service Call Girls AgencyHire 💕 8617697112 North Sikkim Call Girls Service Call Girls Agency
Hire 💕 8617697112 North Sikkim Call Girls Service Call Girls Agency
 
𓀤Call On 6297143586 𓀤 Park Street Call Girls In All Kolkata 24/7 Provide Call...
𓀤Call On 6297143586 𓀤 Park Street Call Girls In All Kolkata 24/7 Provide Call...𓀤Call On 6297143586 𓀤 Park Street Call Girls In All Kolkata 24/7 Provide Call...
𓀤Call On 6297143586 𓀤 Park Street Call Girls In All Kolkata 24/7 Provide Call...
 
Kanpur call girls 📞 8617697112 At Low Cost Cash Payment Booking
Kanpur call girls 📞 8617697112 At Low Cost Cash Payment BookingKanpur call girls 📞 8617697112 At Low Cost Cash Payment Booking
Kanpur call girls 📞 8617697112 At Low Cost Cash Payment Booking
 
Sonagachi ( Call Girls ) Kolkata ✔ 6297143586 ✔ Hot Model With Sexy Bhabi Rea...
Sonagachi ( Call Girls ) Kolkata ✔ 6297143586 ✔ Hot Model With Sexy Bhabi Rea...Sonagachi ( Call Girls ) Kolkata ✔ 6297143586 ✔ Hot Model With Sexy Bhabi Rea...
Sonagachi ( Call Girls ) Kolkata ✔ 6297143586 ✔ Hot Model With Sexy Bhabi Rea...
 
Dum Dum ( Call Girls ) Kolkata ✔ 6297143586 ✔ Hot Model With Sexy Bhabi Ready...
Dum Dum ( Call Girls ) Kolkata ✔ 6297143586 ✔ Hot Model With Sexy Bhabi Ready...Dum Dum ( Call Girls ) Kolkata ✔ 6297143586 ✔ Hot Model With Sexy Bhabi Ready...
Dum Dum ( Call Girls ) Kolkata ✔ 6297143586 ✔ Hot Model With Sexy Bhabi Ready...
 
Navsari Escorts Service ☎️ 6378878445 ( Sakshi Sinha ) High Profile Call Girl...
Navsari Escorts Service ☎️ 6378878445 ( Sakshi Sinha ) High Profile Call Girl...Navsari Escorts Service ☎️ 6378878445 ( Sakshi Sinha ) High Profile Call Girl...
Navsari Escorts Service ☎️ 6378878445 ( Sakshi Sinha ) High Profile Call Girl...
 
📞 Contact Number 8617697112 VIP Ganderbal Call Girls
📞 Contact Number 8617697112 VIP Ganderbal Call Girls📞 Contact Number 8617697112 VIP Ganderbal Call Girls
📞 Contact Number 8617697112 VIP Ganderbal Call Girls
 
Verified Trusted Call Girls Tambaram Chennai ✔✔7427069034 Independent Chenna...
Verified Trusted Call Girls Tambaram Chennai ✔✔7427069034  Independent Chenna...Verified Trusted Call Girls Tambaram Chennai ✔✔7427069034  Independent Chenna...
Verified Trusted Call Girls Tambaram Chennai ✔✔7427069034 Independent Chenna...
 
(TOP CLASS) Call Girls In Nungambakkam Phone 7427069034 Call Girls Model With...
(TOP CLASS) Call Girls In Nungambakkam Phone 7427069034 Call Girls Model With...(TOP CLASS) Call Girls In Nungambakkam Phone 7427069034 Call Girls Model With...
(TOP CLASS) Call Girls In Nungambakkam Phone 7427069034 Call Girls Model With...
 
Hotel And Home Service Available Kolkata Call Girls Park Street ✔ 6297143586 ...
Hotel And Home Service Available Kolkata Call Girls Park Street ✔ 6297143586 ...Hotel And Home Service Available Kolkata Call Girls Park Street ✔ 6297143586 ...
Hotel And Home Service Available Kolkata Call Girls Park Street ✔ 6297143586 ...
 
❤Personal Whatsapp Number Keylong Call Girls 8617697112 💦✅.
❤Personal Whatsapp Number Keylong Call Girls 8617697112 💦✅.❤Personal Whatsapp Number Keylong Call Girls 8617697112 💦✅.
❤Personal Whatsapp Number Keylong Call Girls 8617697112 💦✅.
 
Zirakpur Call Girls👧 Book Now📱8146719683 📞👉Mohali Call Girl Service No Advanc...
Zirakpur Call Girls👧 Book Now📱8146719683 📞👉Mohali Call Girl Service No Advanc...Zirakpur Call Girls👧 Book Now📱8146719683 📞👉Mohali Call Girl Service No Advanc...
Zirakpur Call Girls👧 Book Now📱8146719683 📞👉Mohali Call Girl Service No Advanc...
 
Top Rated Pune Call Girls Dhayari ⟟ 6297143586 ⟟ Call Me For Genuine Sex Ser...
Top Rated  Pune Call Girls Dhayari ⟟ 6297143586 ⟟ Call Me For Genuine Sex Ser...Top Rated  Pune Call Girls Dhayari ⟟ 6297143586 ⟟ Call Me For Genuine Sex Ser...
Top Rated Pune Call Girls Dhayari ⟟ 6297143586 ⟟ Call Me For Genuine Sex Ser...
 
VIP Model Call Girls Koregaon Park ( Pune ) Call ON 8005736733 Starting From ...
VIP Model Call Girls Koregaon Park ( Pune ) Call ON 8005736733 Starting From ...VIP Model Call Girls Koregaon Park ( Pune ) Call ON 8005736733 Starting From ...
VIP Model Call Girls Koregaon Park ( Pune ) Call ON 8005736733 Starting From ...
 
Beautiful 😋 Call girls in Lahore 03210033448
Beautiful 😋 Call girls in Lahore 03210033448Beautiful 😋 Call girls in Lahore 03210033448
Beautiful 😋 Call girls in Lahore 03210033448
 
Top Rated Kolkata Call Girls Dum Dum ⟟ 6297143586 ⟟ Call Me For Genuine Sex S...
Top Rated Kolkata Call Girls Dum Dum ⟟ 6297143586 ⟟ Call Me For Genuine Sex S...Top Rated Kolkata Call Girls Dum Dum ⟟ 6297143586 ⟟ Call Me For Genuine Sex S...
Top Rated Kolkata Call Girls Dum Dum ⟟ 6297143586 ⟟ Call Me For Genuine Sex S...
 
Top Rated Kolkata Call Girls Khardah ⟟ 6297143586 ⟟ Call Me For Genuine Sex S...
Top Rated Kolkata Call Girls Khardah ⟟ 6297143586 ⟟ Call Me For Genuine Sex S...Top Rated Kolkata Call Girls Khardah ⟟ 6297143586 ⟟ Call Me For Genuine Sex S...
Top Rated Kolkata Call Girls Khardah ⟟ 6297143586 ⟟ Call Me For Genuine Sex S...
 
Call Girls Manjri Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Manjri Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Manjri Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Manjri Call Me 7737669865 Budget Friendly No Advance Booking
 
Verified Trusted Call Girls Ambattur Chennai ✔✔7427069034 Independent Chenna...
Verified Trusted Call Girls Ambattur Chennai ✔✔7427069034  Independent Chenna...Verified Trusted Call Girls Ambattur Chennai ✔✔7427069034  Independent Chenna...
Verified Trusted Call Girls Ambattur Chennai ✔✔7427069034 Independent Chenna...
 

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