Chapter 4: Arrays and Strings - PowerPoint PPT Presentation

1 / 4
About This Presentation
Title:

Chapter 4: Arrays and Strings

Description:

String concatenation: JoinStrings.java. String matching: MatchStrings.java & Identity! ... To concatenate use append() To insert use insert(): buf.insert(5, 'ttt' ... – PowerPoint PPT presentation

Number of Views:58
Avg rating:3.0/5.0
Slides: 5
Provided by: far71
Category:

less

Transcript and Presenter's Notes

Title: Chapter 4: Arrays and Strings


1
Chapter 4 Arrays and Strings
2
Basics of Arrays
  • Declaration int myArray or int myArray
  • Definition int myArray new int10
  • Accessing num myArrayi I should be int
  • Array bound check!!!
  • Reusing the array myArray new int100
  • Initializing int myArray 1, 2, 3
  • Array length myArray.length
  • Examples MorePrimes.java WeatherFan.java
  • Array of characters char vowels a, e,
    I, o, u

3
Strings
  • String Literals This is a string
  • Declare String String myString
  • Initialize String String myString My String
  • Arrays of Strings String names new
    String5
  • String concatenation JoinStrings.java
  • String matching MatchStrings.java Identity!
  • String comparison SequenceString.java
  • String searching FindCharacters.java
  • Extracting Strings ExtractSubstring.java

4
StringBuffer Class
  • It is a class that looks like the String class
    but it is not a static one
  • Operations (concat., etc.) are much more
    efficient using StringBuffer
  • Default capacity is 16 StringBuffer buffer new
    StringBuffer()
  • length() and capacity() may vary
  • To concatenate use append()
  • To insert use insert() buf.insert(5, ttt)
  • To convert to String object use toString()
Write a Comment
User Comments (0)
About PowerShow.com