Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Array / Array list  RSS feed

 
Chase Becicka
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have been doing java for a little now and we haved moved onto array's and array lists. I am a little comfused about how to extract objects from an array or an array list once they have been inputed in. I have been told that items always come out as objects so if anyone could just show me some basic lines with object extraction it would really help

Animal2[] animals = new Animal2[5];
animals[0] = w;
animals[1] = d;
animals[2] = p;

This is my portion of code setting my objects into their array
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You've alread demonstrated the syntax used to access an array element. It's the same whether you are "reading" or "writing" that element:

You can also call methods directly on the array element:

Using ArrayLists involve some more details. The above example illustrates the basics, so I encourage you to look into it a little.

I sure hope this helps get you on the way. For more information on the methods offered by ArrayList. You should check out the API documentation. In fact, this is a great resource to find out what classes and methods are offered by the standard API. For ArrayList, you should navigate to the java.util package.

Let us know if you have any more questions.

Layne
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!