DOC PREVIEW
TRINITY CSCI 1321 - Strings and Arrays

This preview shows page 1-2-3 out of 8 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 8 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 8 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 8 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 8 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

1Strings and Arrays2/7/20082Opening Discussion■Do you have any questions about the assignment?■What is the purpose of generics?■What is the syntax of generics?■What are enums?■What is the syntax of Java enums?■What are inner classes? What makes them special? What types of inner classes are there?■What is the syntax of inner classes?3Strings■How did you represent a string in C? How do we represent a string in Java?■Let's go look at the API for String to see what the Java developers have provided us with.■Strings are immutable so it is very inefficient to build big strings from a lot of little pieces. If you need to do that, use StringBuffer.■It is the only class with an overloaded operator, + for string concatenation.■Functions that looks they mutate the String return a new String instead.■To get a single character, use charAt.4Code■To give us a chance to play with strings some let's go ahead and write that code that parses text formulas into a polymorphic tree for fast evaluation.5Regular Expressions■You'll notice that some of the methods in String say that they take regular expressions (regex). This is a topic that we won't directly cover in this class, but it is a very powerful technique for you to learn.■The java.util.regex package contains the two main classes that are used for regular expressions. The Pattern class has a lot of description about them at the top.6Arrays■Array syntax in Java is just like it was in C as far as using the arrays. There are significant differences though.■Array types are made by putting [] after a regular type.■Array types are object types so your variables are references and should be instantiated with new.■Arrays have bounds checking and know their length.■You can't make arrays of generics.7Code■With whatever time is left I want to go play with the ray tracer some now. We can make an array of Geomerty objects.■Note that arrays of objects store an array of references. This allows for inclusion polymorphism with arrays.8Minute Essay■Write the following method:String replaceAll(String s,char f,char t)■This method should return a new string where all instances of f in s have been replaced with t.■Remember to submit your code for assignment #1 today.■The first quiz is next class.■Interclass Problem – Write a program where a user types in a line of text and you print out each word in the line and the number of characters in


View Full Document

TRINITY CSCI 1321 - Strings and Arrays

Documents in this Course
Recursion

Recursion

11 pages

Iterators

Iterators

10 pages

Actors

Actors

9 pages

Recursion

Recursion

15 pages

Recursion

Recursion

10 pages

Threads

Threads

7 pages

Trees

Trees

11 pages

Load more
Download Strings and Arrays
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Strings and Arrays and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Strings and Arrays 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?