I have the following program:
public static void main (
String[] args)
{
ArrayList name = new ArrayList();
name.add ("Jim");
name.add ("David");
name.add ("Eddy");
name.add ("Murphy");
name.add ("David");
name.add("Don");
System.out.println (name);
I have to find all of the Array list indices where 'David' occurs and print these. I will need to loop through the ArrayList getting each entry and checking to see if it is 'David'. I have to use the method .equals to compare Strings, not == (this can only be used for primitive data types), need help to convert the below program to use equals method..
for (int i=0; i<band.size(); i++)
{
String str = "David";
if (band.get(i) ==(str))
{
System.out.println("The Strings are equal");
}
else
{
System.out.println("The Strings are not equal");
}
}