3 Replies - 1245 Views - Last Post: 22 October 2012 - 02:25 PM Rate Topic: -----

#1 LadyBee  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 19
  • Joined: 09-October 12

how to access to the specified index of the array of the ArrayList

Posted 21 October 2012 - 11:31 PM

Hi,

I am trying to acces to the specified index of the array of the ArrayList and then I would like to assign it tot the specific
variable, course name. This is what I am doing:
String courseName;
for(int i = 0; i< dlayer.getStudentList().getContainer().size(); i++)
{
	courseName = dlayer.getStudentList().getContainer().get(i)[2]; 
        //error: The type of the expression must be an array type but it resolved to Object



//then I am planning to do other things in the loop with that courseName but first 
//I need to find the way how to assign some data to it
}



Thank you for help

Is This A Good Question/Topic? 0
  • +

Replies To: how to access to the specified index of the array of the ArrayList

#2 RozenKristal  Icon User is offline

  • D.I.C Regular

Reputation: 45
  • View blog
  • Posts: 317
  • Joined: 29-September 12

Re: how to access to the specified index of the array of the ArrayList

Posted 21 October 2012 - 11:56 PM

So to get a value from an index of an array list, you can:
get

public E get(int index)
Returns the element at the specified position in this list.


I dont know why you doing
 courseName = dlayer.getStudentList().getContainer().get(i)[2];


arraylist dont use [index] to go arround. get(index) will give you the value of the specific index.
Was This Post Helpful? 1
  • +
  • -

#3 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8324
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: how to access to the specified index of the array of the ArrayList

Posted 22 October 2012 - 03:43 AM

for that stemen to be valid

courseName = dlayer.getStudentList().getContainer().get(i)[2];

dlayer.getStudentList().getContainer().get(i) has to return an array of String
so getContainer() has to be a ArrayList<String[]>
Was This Post Helpful? 1
  • +
  • -

#4 LadyBee  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 19
  • Joined: 09-October 12

Re: how to access to the specified index of the array of the ArrayList

Posted 22 October 2012 - 02:25 PM

You are right that to get a value from an index of an array list, you can:
get

public E get(int index)
Returns the element at the specified position in this list.


but the thing is you get all the data which is on the specific index of the ArrayList.
I was doing as you described but I was getting all the data from the specific index line.
The thing is that I wanted to get the specific value from the specific index of the array which is in the ArrayList.
It is the reason I used
 courseName = dlayer.getStudentList().getContainer().get(i)[2]; 

Also, the reason why I used the code above because I found similar idea in other forum.

thank you for trying to help.!!!!!

Thank you. it worked in my code.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1