SlideShare a Scribd company logo
1 of 17
Strings & Arrays
CST200 – Week 1
Instructor: Andreea Molnar
Outline
• Strings
• Arrays
Strings and Arrays
The first letter of a String is at the
position 0 and the first value of an array
is at the position 0.
Strings
Any sequence of characters, for example:
String s = “Arizona”;
String s = “1457 Mesa”;
String s = “@u”;
Escape Sequences
Escape sequence Meaning
b backspace
t tab
n newline
r return
’’ double quote
’ single quote
 backslash
Escape Sequences
String firstName = "Mary";
String lastName = "Smith";
System.out.println(firstName + "t" + lastName);
Mary Smith
System.out.println(firstName + "n" + lastName);
Mary
Smith
System.out.println(firstName + """ + lastName);
Mary"Smith
System.out.println(firstName + "" + lastName);
MarySmith
Strings - Methods
You can find all the String methods at:
http://docs.oracle.com/javase/7/docs/api/j
ava/lang/String.html
Strings - Methods
public int length() – returns the length of the
string
String s = “CST 200”;
s.length() – will return 7 as there are 7
characters in the string
Strings - Methods
public int length() – returns the length of the
string
String s = “CST 200”;
s.length() – will return 7 as there are 7
characters in the string (space is counted
as a separate character)
Strings - Methods
public char charAt(int index)– returns the
character value at the specified index
String s = “CST 200”;
C S T 2 0 0
0 1 2 3 4 5 6
index
Strings - Methods
public char charAt(int index)– returns the
character value at the specified index
String s = “CST 200”;
C S T 2 0 0
0 1 2 3 4 5 6
The first character of a String is at the
position 0!!!
Strings - Methods
String s = “CST 200”;
C S T 2 0 0
0 1 2 3 4 5 6
System.out.println(s.charAt(0));//will print C
System.out.println(s.charAt(6));//will print 0
Strings - Methods
String indexOf (String str)
returns the index of the first occurrence of str
if multiple occurrences returns just the first one
String s = “CST 200”;
C S T 2 0 0
0 1 2 3 4 5 6
System.out.println(s.indexOf(“T”));
//will print 2
String Methods
String substring(int beginIndex, int endIndex)
returns a substring that begins at the
beginIndex and ends at the endIndex -1
String str = “Arizona State University”;
str.substring (3, 5); //substring that begins at the index 3
(z) and ends at the 5-1 (o)  zo
Arrays
Array is a container that holds a fixed
number of values.
int[] array = {10, 20, 30, 50};
10 20 30 50
0 1 2 3
index
Arrays
int[] array = {10, 20, 30, 50};
10 20 30 50
0 1 2 3
To print the values of this array:
System.out.println(array[0]);//will print 10
System.out.println(array[1]);//will print 20
System.out.println(array[2]);//will print 30
System.out.println(array[3]);//will print 50
Summary
• The first character of a String starts at
position 0
• The first element of an array starts at
the position 0

More Related Content

Viewers also liked

History Of Linux
History Of LinuxHistory Of Linux
History Of Linuxanand09
 
Compiler Design Introduction
Compiler Design IntroductionCompiler Design Introduction
Compiler Design IntroductionRicha Sharma
 
Learning sed and awk
Learning sed and awkLearning sed and awk
Learning sed and awkYogesh Sawant
 
Pointer in c program
Pointer in c programPointer in c program
Pointer in c programRumman Ansari
 
Top down and botttom up Parsing
Top down     and botttom up ParsingTop down     and botttom up Parsing
Top down and botttom up ParsingGerwin Ocsena
 
Input, Output Ppt
Input, Output PptInput, Output Ppt
Input, Output PptLisa Durff
 
Basic command ppt
Basic command pptBasic command ppt
Basic command pptRohit Kumar
 
Presentation on Input and Output Devices
Presentation on Input and Output DevicesPresentation on Input and Output Devices
Presentation on Input and Output DevicesZobia Aziz
 
C language control statements
C language  control statementsC language  control statements
C language control statementssuman Aggarwal
 
Decision Making Process
Decision Making ProcessDecision Making Process
Decision Making ProcessAima Masood
 
DECISION MAKING POWERPOINT
DECISION MAKING POWERPOINT DECISION MAKING POWERPOINT
DECISION MAKING POWERPOINT Andrew Schwartz
 
Motherboard and its components
Motherboard and its componentsMotherboard and its components
Motherboard and its componentsJishnu Pradeep
 

Viewers also liked (16)

Basic 50 linus command
Basic 50 linus commandBasic 50 linus command
Basic 50 linus command
 
History Of Linux
History Of LinuxHistory Of Linux
History Of Linux
 
Compiler Design Introduction
Compiler Design IntroductionCompiler Design Introduction
Compiler Design Introduction
 
Learning sed and awk
Learning sed and awkLearning sed and awk
Learning sed and awk
 
Pointer in c program
Pointer in c programPointer in c program
Pointer in c program
 
C pointer
C pointerC pointer
C pointer
 
Top down and botttom up Parsing
Top down     and botttom up ParsingTop down     and botttom up Parsing
Top down and botttom up Parsing
 
Phases of Compiler
Phases of CompilerPhases of Compiler
Phases of Compiler
 
Input and output devices
Input and output devicesInput and output devices
Input and output devices
 
Input, Output Ppt
Input, Output PptInput, Output Ppt
Input, Output Ppt
 
Basic command ppt
Basic command pptBasic command ppt
Basic command ppt
 
Presentation on Input and Output Devices
Presentation on Input and Output DevicesPresentation on Input and Output Devices
Presentation on Input and Output Devices
 
C language control statements
C language  control statementsC language  control statements
C language control statements
 
Decision Making Process
Decision Making ProcessDecision Making Process
Decision Making Process
 
DECISION MAKING POWERPOINT
DECISION MAKING POWERPOINT DECISION MAKING POWERPOINT
DECISION MAKING POWERPOINT
 
Motherboard and its components
Motherboard and its componentsMotherboard and its components
Motherboard and its components
 

Similar to Strings & arrays

Similar to Strings & arrays (20)

Learn Java Part 6
Learn Java Part 6Learn Java Part 6
Learn Java Part 6
 
String and string manipulation
String and string manipulationString and string manipulation
String and string manipulation
 
Python - Lecture 5
Python - Lecture 5Python - Lecture 5
Python - Lecture 5
 
String and string manipulation x
String and string manipulation xString and string manipulation x
String and string manipulation x
 
Strings CPU GTU
Strings CPU GTUStrings CPU GTU
Strings CPU GTU
 
Strings v.1.1
Strings v.1.1Strings v.1.1
Strings v.1.1
 
Team 1
Team 1Team 1
Team 1
 
L13 string handling(string class)
L13 string handling(string class)L13 string handling(string class)
L13 string handling(string class)
 
String slide
String slideString slide
String slide
 
Write a class of static methods that accomplish the following tasks. .docx
 Write a class of static methods that accomplish the following tasks. .docx Write a class of static methods that accomplish the following tasks. .docx
Write a class of static methods that accomplish the following tasks. .docx
 
Module-2_Strings concepts in c programming
Module-2_Strings concepts in c programmingModule-2_Strings concepts in c programming
Module-2_Strings concepts in c programming
 
Strings.ppt
Strings.pptStrings.ppt
Strings.ppt
 
Week6_P_String.pptx
Week6_P_String.pptxWeek6_P_String.pptx
Week6_P_String.pptx
 
M C6java7
M C6java7M C6java7
M C6java7
 
13 Strings and text processing
13 Strings and text processing13 Strings and text processing
13 Strings and text processing
 
week-7x
week-7xweek-7x
week-7x
 
Python programming : Strings
Python programming : StringsPython programming : Strings
Python programming : Strings
 
Strings in Python
Strings in PythonStrings in Python
Strings in Python
 
Python data handling
Python data handlingPython data handling
Python data handling
 
Strings in C language
Strings in C languageStrings in C language
Strings in C language
 

More from andreeamolnar

More from andreeamolnar (6)

Lists, queues and stacks
Lists, queues and stacksLists, queues and stacks
Lists, queues and stacks
 
For loop java
For loop javaFor loop java
For loop java
 
Classes revision
Classes revisionClasses revision
Classes revision
 
Reading and writting
Reading and writtingReading and writting
Reading and writting
 
Division
DivisionDivision
Division
 
Common errors
Common errorsCommon errors
Common errors
 

Recently uploaded

AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesVictorSzoltysek
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension AidPhilip Schwarz
 
Pharm-D Biostatistics and Research methodology
Pharm-D Biostatistics and Research methodologyPharm-D Biostatistics and Research methodology
Pharm-D Biostatistics and Research methodologyAnusha Are
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdfPearlKirahMaeRagusta1
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfonteinmasabamasaba
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionOnePlan Solutions
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfkalichargn70th171
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verifiedSector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verifiedDelhi Call girls
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfonteinmasabamasaba
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrainmasabamasaba
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park masabamasaba
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisamasabamasaba
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park masabamasaba
 

Recently uploaded (20)

AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
Pharm-D Biostatistics and Research methodology
Pharm-D Biostatistics and Research methodologyPharm-D Biostatistics and Research methodology
Pharm-D Biostatistics and Research methodology
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verifiedSector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 

Strings & arrays

  • 1. Strings & Arrays CST200 – Week 1 Instructor: Andreea Molnar
  • 3. Strings and Arrays The first letter of a String is at the position 0 and the first value of an array is at the position 0.
  • 4. Strings Any sequence of characters, for example: String s = “Arizona”; String s = “1457 Mesa”; String s = “@u”;
  • 5. Escape Sequences Escape sequence Meaning b backspace t tab n newline r return ’’ double quote ’ single quote backslash
  • 6. Escape Sequences String firstName = "Mary"; String lastName = "Smith"; System.out.println(firstName + "t" + lastName); Mary Smith System.out.println(firstName + "n" + lastName); Mary Smith System.out.println(firstName + """ + lastName); Mary"Smith System.out.println(firstName + "" + lastName); MarySmith
  • 7. Strings - Methods You can find all the String methods at: http://docs.oracle.com/javase/7/docs/api/j ava/lang/String.html
  • 8. Strings - Methods public int length() – returns the length of the string String s = “CST 200”; s.length() – will return 7 as there are 7 characters in the string
  • 9. Strings - Methods public int length() – returns the length of the string String s = “CST 200”; s.length() – will return 7 as there are 7 characters in the string (space is counted as a separate character)
  • 10. Strings - Methods public char charAt(int index)– returns the character value at the specified index String s = “CST 200”; C S T 2 0 0 0 1 2 3 4 5 6 index
  • 11. Strings - Methods public char charAt(int index)– returns the character value at the specified index String s = “CST 200”; C S T 2 0 0 0 1 2 3 4 5 6 The first character of a String is at the position 0!!!
  • 12. Strings - Methods String s = “CST 200”; C S T 2 0 0 0 1 2 3 4 5 6 System.out.println(s.charAt(0));//will print C System.out.println(s.charAt(6));//will print 0
  • 13. Strings - Methods String indexOf (String str) returns the index of the first occurrence of str if multiple occurrences returns just the first one String s = “CST 200”; C S T 2 0 0 0 1 2 3 4 5 6 System.out.println(s.indexOf(“T”)); //will print 2
  • 14. String Methods String substring(int beginIndex, int endIndex) returns a substring that begins at the beginIndex and ends at the endIndex -1 String str = “Arizona State University”; str.substring (3, 5); //substring that begins at the index 3 (z) and ends at the 5-1 (o)  zo
  • 15. Arrays Array is a container that holds a fixed number of values. int[] array = {10, 20, 30, 50}; 10 20 30 50 0 1 2 3 index
  • 16. Arrays int[] array = {10, 20, 30, 50}; 10 20 30 50 0 1 2 3 To print the values of this array: System.out.println(array[0]);//will print 10 System.out.println(array[1]);//will print 20 System.out.println(array[2]);//will print 30 System.out.println(array[3]);//will print 50
  • 17. Summary • The first character of a String starts at position 0 • The first element of an array starts at the position 0