New to Programming .. Passing an array of objects into a method?

  • (2 Pages)
  • +
  • 1
  • 2

19 Replies - 829 Views - Last Post: 20 May 2012 - 12:41 PM Rate Topic: -----

#16 MaccaTractor  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 19-May 12

Re: New to Programming .. Passing an array of objects into a method?

Posted 19 May 2012 - 11:27 PM

Don't worry :) i just had to get rid of the ";" at the end of my if statement
Was This Post Helpful? 0
  • +
  • -

#17 GregBrannon  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2001
  • View blog
  • Posts: 4,868
  • Joined: 10-September 10

Re: New to Programming .. Passing an array of objects into a method?

Posted 19 May 2012 - 11:36 PM

if (subjectCode == (codes [i].substring (0,3)));
disciplineCodes.add (codes [i].substring (3,6));

The semi-colon at the end of the statement ends the if clause. It's not always returning true, but the next line always executes, because it's not part of the 'if' clause.

Use the equal() method to compare objects:
if ( subjectCode.equals( (codes[i].substring(0,3)) ) );
Was This Post Helpful? 2
  • +
  • -

#18 MaccaTractor  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 19-May 12

Re: New to Programming .. Passing an array of objects into a method?

Posted 19 May 2012 - 11:53 PM

I love this forum :)! Thanks heaps!!
Was This Post Helpful? 0
  • +
  • -

#19 uzumaki07  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 19-May 12

Re: New to Programming .. Passing an array of objects into a method?

Posted 20 May 2012 - 01:32 AM

Hey guys,


Thank you for posting this discussion here, I'm also having with this type of problem....but now I've seen you're discussion, I know what to do with my source code
Was This Post Helpful? 0
  • +
  • -

#20 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 9155
  • View blog
  • Posts: 33,967
  • Joined: 27-December 08

Re: New to Programming .. Passing an array of objects into a method?

Posted 20 May 2012 - 12:41 PM

Quote

Use the equal() method to compare objects:
if ( subjectCode.equals( (codes[i].substring(0,3)) ) );

Expanding on this some. With Objects, the == operator compares their memory locations, not their literal values. The equals() method in Object does the same thing. However, most classes (like String) override the equals() method to compare Objects based on their actual values, not their locations in memory.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2