-1

My Variable c is always zero. I dont understand why its not updating. can anyone please explain why this is happening. what should i do to avoid this

public static int linearSearch(Exam[] marks, String name) {
    int c =0;
    if( marks==null)
    {

        return -1;

    }
    else{

        for(int i=0;i<marks.length;i++)
        {

            //System.out.println(a[i]);
            if(performances[i].getName()==name)
            {
                c= i;

            }

        }
    }
    return c;


    //to be completed
}
ananymous59
  • 200
  • 1
  • 14

1 Answers1

4

Modify this line as below

performances[i].getName().equalsIgnoreCase(name)

if you want to Ignore upper or lower case

else use the below

performances[i].getName().equals(name)

to check the content of the name instead of references.

Jordi Castilla
  • 26,609
  • 8
  • 70
  • 109
Mohan Raj
  • 1,104
  • 9
  • 17
  • 2
    Should be `.equals(name)` or `.equalsIgnoreCase(name)`, **not** `.equalIgnorecase(name)` - the capital 'C' matters. – JonK Apr 30 '15 at 14:39