Lecture 13 (Edwards) - String Methods and Methods in General

Lecture Date: Monday, March 2

Today we will be going over the test and talk about re-grades. The key is available on collab.

We will then talk about String methods such as indexOf, lastIndexOf, substring, and replace. Note that many of these will be helpful for the project!

You can also look at the String API

Next we will talk about methods in general, note that we have been using methods all year (not just today)! For example:

Turtle Example
Turtle t = new Turtle();

This is something we did with turtle notice the () at the end, this means it is a method.

Lets wirte our own version of indexOf.

public static int findChar(String s, char c)

We have talked about public before, it just means that it is accessable to other classess.

static just means that the method belongs to the class, as in Math.pow (instead of say NameOfClass.nameOfMethod() such as name.charAt(3) where name is a String).

int is the return type. return is a key word in Java. If a method does not return then we need to say void in the method signature.

findChar is the name of the method.

(String s, char c) is a list of all the parameters that are passed. Note that two methods can have the same name if they have different parameters.

Code from class: