Q:

Searching through an ArrayList

Implement a method
public void search (String searchString) { }

to iterate through the notes ArrayList until it
  finds a note that contains the searchString.
  It should then print either the item found or
  the message "String not found".

So far, I have:
import java.util.ArrayList;
import java.util.Iterator;

/**
 * A class to maintain an arbitrarily long list of notes.
 * Notes are numbered for external reference by a human user.
 * In this version, note numbers start at 0.
 * 
 * @author David J. Barnes and Michael Kolling.
 * @version 2008.03.30
 */
public class Notebook
{
    // Storage for an arbitrary number of notes.
    private ArrayList<String> notes;

    /**
     * Perform any initialization that is required for the
     * notebook.
     */
    public Notebook()
    {
        notes = new ArrayList<String>();
    }

    /**
     * Store a new note into the notebook.
     * @param note The note to be stored.
     */
    public void storeNote(String note)
    {
        notes.add(note);
    }

    /**
     * @return The number of notes currently in the notebook.
     */
    public int numberOfNotes()
    {
        return notes.size();
    }

    /**
     * Show a note.
     * @param noteNumber The number of the note to be shown.
     */
    public void showNote(int noteNumber)
    {
        if(noteNumber < 0) {
            // This is not a valid note number, so do nothing.
            System.out.println("invalid index given");
        }
        else if(noteNumber < numberOfNotes()) {
            // This is a valid note number, so we can print it.
            System.out.println(notes.get(noteNumber));
        }
        else {
             System.out.println("there are fewer items in the notebook");
            // This is not a valid note number, so do nothing.
        }
    }

    public void removeNote(int noteNumber)
    {
        if(noteNumber < 0) {
            // This is not a valid note number, so do nothing.
             System.out.println("invalid index given");
        }
        else if(noteNumber < numberOfNotes()) {
            // This is a valid note number.
            notes.remove(noteNumber);
        }
        else {
            System.out.println("there are fewer items in the notebook");
            // This is not a valid note number, so do nothing.
        }
    }

    /* Edit note.
     * I tried to improve the formatting of the code below, but I'm completely
     * unable to figure out how on earth anything of that should make sense
     * and therefore the indentation is completely without any meaning.
     */
    public void search (String searchString)
    { 
        for each notes in ArrayList {    
            if notes = searchString;        
                System.out.println("String found"); + searchString        
                return    end 
            }
        if}
        System.out.println("String not found");
    }
}

But it is not working, and I am not able to work it out.  

A:

Several problems:

Your search method is actually outside the class.
The body of your search method makes no sense at all.

If you're counting on the monkeys writing Shakespeare, you'll be waiting a while.

A:

To iterate over the array list, you can use a 'for-each' loop:
for (String note: notes) {
    // Do something with note
}

This is very basic syntax. Have you seen it before? If not, you should start by reading a very basic tutorial to Java before attempting this homework.

A:

Fundamentally you need to look at each item in your ArrayList and test to see if it matches the search condition.  In Pseudocode
for each note in notes
{
    if note equals searchString then 
        print "Found " + searchString
        return
    end if
}

print "not found"

Given that basic outline, want to take a second stab at coding it in Java?

