Converting search method to find strings instead of integers

I'm writing a class, which currently includes a search method for finding integer variables within a text file. I need to change this to find strings in the same text file. I've tried changing this method, but have had no luck so far. The current code for the search method is as follows,

public Title lookUp2(String requiredDetails){

boolean found =false;

int next = 0;

while (!found && (next<TitleCount))

{

if ( TitleArray[next].getFilmName() == requiredDetails)

found =true;

else next++;

}

if (found)return TitleArray[next];

elsereturnnull;

}

The constructors for this class are currently,

public TitleList_1(int max){

TitleCount = 0; maxTitles=max;

TitleArray =new Title[max];

}

public TitleList_1(){

this(1000000);

}

public TitleList_1(SimpleReader in){

this(in.readInt());

int entries = in.readInt();

for (int i = 0; i><entries; i++)

add(new Title(in));

}

Any advice or help on how to change the above search method to allow me to search for strings as well as integers.>

[2231 byte] By [jackna] at [2007-10-2 6:43:18]
# 1
You need to use .equals to compare Strings, not "==".if ( TitleArray[next].getFilmName().equals(requiredDetails))
MLRona at 2007-7-16 13:51:44 > top of Java-index,Java Essentials,Java Programming...
# 2

Hi,

Thanks for the reply. I have substituted .equals for == in my search method, but when I call this method in the test main class, I still get an error message. Basically, the title cannot be found in the list.

It returns 'Not Found' as specified in the main class for any title supposedly not in the title text file.

Any ideas why this might be happening. The code for my test main class is as follows,

import simplejava.*;

public class SearchTitle_1

{

public static void main(String[] args) {

int titleCode;

String titleDetails;

SimpleReader keyboard = new SimpleReader();

SimpleWriter screen = new SimpleWriter();

SimpleReader inFile = new SimpleReader("title_test.txt");

TitleList title = new TitleList(inFile);

titleDetails=keyboard.readLine("Film Title?");

Title search = title.lookUp2(titleDetails);

if (search == null)

screen.println("Not found");

else screen.println(search);

}

}

Many thanks for the help!

jackna at 2007-7-16 13:51:44 > top of Java-index,Java Essentials,Java Programming...
# 3
Hi,Has anybody got any advice or help for this problem?Thank you
jackna at 2007-7-16 13:51:44 > top of Java-index,Java Essentials,Java Programming...
# 4
I'm so happy.I've managed to figure this one out by myself. The search method in effect had nothing to search, so I created an array of type TitleList in the main class, and allowed the search method access to the details in there. It now works as planned. Yeah!!
jackna at 2007-7-16 13:51:44 > top of Java-index,Java Essentials,Java Programming...
# 5
Congratulations, and good work!
targaryena at 2007-7-16 13:51:44 > top of Java-index,Java Essentials,Java Programming...
# 6
Thank you. Have a great weekend!
jackna at 2007-7-16 13:51:44 > top of Java-index,Java Essentials,Java Programming...