Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
2
Question by Zach Meyers · Feb 10, 2011 at 04:32 AM · arrayarraylist

Array vs ArrayList

Hey guys,

Im relatively new to programming, especially in UnityScript. I am confused on when to use the Array function and the ArrayList function. I am not even sure of what an ArryList is. I do know that an Array is a container in which variables can be placed, with the first variable having position 0. When should i use an Array and when should i use an ArrayList?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

3 Replies

· Add your reply
  • Sort: 
avatar image
3
Best Answer

Answer by Eric5h5 · Feb 10, 2011 at 05:11 AM

You shouldn't use either Array or ArrayList; they're basically the same thing. You should use fixed-length built-in arrays (int[], float[], etc.) where possible, but if you need to be able to change the length of the array (insert/delete elements, etc.), use generic Lists. The one thing Array/ArrayList can do that the other kinds of arrays can't is store multiple different types of objects in the same array. But you almost never actually need to do that, and the performance cost of doing this is relatively high, so stick with built-in arrays and Lists as appropriate. (In the same vein, don't use Hashtable, use Dictionary instead, for basically the same reason.)

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ina · May 08, 2011 at 05:16 AM 0
Share

i'm still not sure why you shouldn't use arraylist - it seems the best way to store instances of gameobjects

avatar image Eric5h5 · May 08, 2011 at 05:23 AM 0
Share

@ina: No, because it's slow and not type safe. GameObject[] is the best way to store instances of gameobjects, assu$$anonymous$$g you have a fixed number. If not, then List probably is (depending on what you're doing, maybe LinkedList or some other type), but never ArrayList.

avatar image
0

Answer by Justin Warner · Feb 10, 2011 at 04:48 AM

Um, ArrayList is more adaptable... Like, you can add and remove objects with ease through an ArrayList, while an array, once a size, is always that size...

Also, people around here use List more so than ArrayList (I personally have always used ArrayList in school).

www.Google.com can help you further about what the differences are =).

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Zach Meyers · Feb 10, 2011 at 05:01 AM 0
Share

Thats what I thought. Im still confused on when to use either or? Or does it not matter which one I use?

avatar image
0

Answer by Arowx · Mar 03, 2011 at 01:52 AM

ArrayList can be resized and therefore is slower, Arrays can't be resized* but are very fast.

Choosing your container depends on how you use it and what you use it for..

Generally

Stack/Queue - When you just need the next item to work with one at a time List - Slow to add to but good for looping through Array - Get fast access to items at an index Hashmap - Use unique keys to get items

So the answer is it depends on what and how you intend to use the container...

PS Using the right container for the right job can make your code faster and easier! * You can make a new larger one but if you need to keep doing this your probably using the wrong container ;o)

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Eric5h5 · Mar 03, 2011 at 02:11 AM 0
Share

This is about Array in JS, which can be resized. Not built-in arrays in $$anonymous$$ono. As I said in my answer, Array and ArrayList are basically the same. Probably Array is just a wrapper for ArrayList.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

Storing Level Data in Array of Array (grid-based game) 1 Answer

Collections don't work! 1 Answer

Question about updating particles in an arraylist 0 Answers

Print arraylist values to console 4 Answers

How to get smallest element and key from int list 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges