Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

String and StringBuffer - Introduction to Programming in Java | CSIS 110, Study notes of Javascript programming

Material Type: Notes; Professor: Hanks; Class: Intro to Programming in Java; Subject: Computer Science Info Systems; University: Fort Lewis College; Term: Fall 2005;

Typology: Study notes

Pre 2010

Uploaded on 08/05/2009

koofers-user-f8a-1
koofers-user-f8a-1 🇺🇸

5

(1)

10 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CSIS 110 – Lecture 36
Announcements
Part 2 of the last programming assignment is on the course web site.
I have put my recent notes on-line also.
String and StringBuffer
Let’s go back a revisit the String class. What are some methods provided by this class?
What do methods such as toUpperCase and toLowerCase do? They return new Strings –
the original String is unchanged.
Strings are said to be immutable – once you have created one, you can't modify it. (You
can change what the String references, but you can't modify the String itself).
The StringBuffer class is similar to String, except that StringBuffer objects can be
modified. Let's look at some methods provided by the StringBuffer class:
append – add some characters to the end of the StringBuffer
insert – insert characters in the middle of the StringBuffer
setCharAt – change the character at position p to a new value
deleteCharAt – delete the character at position p
toString – return a String representation of the StringBuffer
Also has methods like the String class: length, charAt.
Constructor: unlike Strings, we can only create StringBuffer objects using the
constructor:
StringBuffer()
StringBuffer( String s )
pf2

Partial preview of the text

Download String and StringBuffer - Introduction to Programming in Java | CSIS 110 and more Study notes Javascript programming in PDF only on Docsity!

CSIS 110 – Lecture 36

Announcements Part 2 of the last programming assignment is on the course web site. I have put my recent notes on-line also. String and StringBuffer Let’s go back a revisit the String class. What are some methods provided by this class? What do methods such as toUpperCase and toLowerCase do? They return new Strings – the original String is unchanged. Strings are said to be immutable – once you have created one, you can't modify it. (You can change what the String references, but you can't modify the String itself). The StringBuffer class is similar to String, except that StringBuffer objects can be modified. Let's look at some methods provided by the StringBuffer class: append – add some characters to the end of the StringBuffer insert – insert characters in the middle of the StringBuffer setCharAt – change the character at position p to a new value deleteCharAt – delete the character at position p toString – return a String representation of the StringBuffer Also has methods like the String class: length, charAt. Constructor: unlike Strings, we can only create StringBuffer objects using the constructor: StringBuffer() StringBuffer( String s )

Lab Create a new project. Create a new class named RemoveJ. This class should have one public method: public String removeJ( String str ) The removeJ method should return a String which is the same as the String str with the letter J removed. Remove both upper and lower case Js. Your method should do the following: Create a StringBuffer initialized to the value of str. Manipulate the StringBuffer to remove the Js. Return a String that contains the contents of the StringBuffer. Test your method using the Automated unit testing features of BlueJ. Email your RemoveJ.java and TestRemoveJ.java files to me.