2 Replies - 1082 Views - Last Post: 08 October 2012 - 02:54 PM

#1 Alexey_Shevelyov-  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 21-April 12

Getting Value of an Array Element

Posted 07 October 2012 - 01:30 AM

So there is a

Array<Student> called stu

that has 2 student objects in there [0], [1]

One of the elements that Studet[0] has (as well as Student [1]) is

String sid which is equal to "2345"

Studet[0] also has double Q1 = 95.0

1) String ut = stu[0].sid; // Why it does not give me the sid value "2345"?

My goal is to get the sid value of stu[0]?

What are my options here?

Is This A Good Question/Topic? 0
  • +

Replies To: Getting Value of an Array Element

#2 blackcompe  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1131
  • View blog
  • Posts: 2,484
  • Joined: 05-May 05

Re: Getting Value of an Array Element

Posted 07 October 2012 - 03:30 AM

Please don't create duplicate threads. Post questions related to your first thread in that thread. As for your question, you should try using a debugger. Without the code in full, there's no way to know what's causing the problem.

Quote

My goal is to get the sid value of stu[0]?


If the class Student has a field name sid, and you've got an array of Students named studentArray, then studentArray[0].sid is want you want.

This post has been edited by blackcompe: 07 October 2012 - 03:45 AM

Was This Post Helpful? 0
  • +
  • -

#3 rfs02  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 26
  • View blog
  • Posts: 70
  • Joined: 30-September 12

Re: Getting Value of an Array Element

Posted 08 October 2012 - 02:54 PM

Is this supposed to be an ArrayList<Student> or a Student[]?

If you're using ArrayList<Student>, you cannot use brackets to retrieve objects, you have to use the get method.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1