![]() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]()
![]() |

|
| Programming tutorials All Knowledge Info and links to posted here |
![]() |
|
Arrays in Java
|
LinkBack | Thread Tools | Display Modes |
|
|
#1 (permalink) |
|
Administrator
Posts: 18,715
Join Date: Jan 2006
Rep Power: 10
IM:
|
Arrays let you hold multiple objects. Say you want to hold a bunch of numbers, instead of having a bunch of scattered int objects, you can use an array and hold it all in an organized fashion. Arrays only let you hold one specific type of object, so you can't hold integers and Strings in one array. Also, arrays let you only hold a set limit of objects, so if you make the array have ten spots, you can only hold a max of ten objects and can never make more space. Of course you don't have to necessarily hold a object in an array spot. So how do you create an array: here is an example int myArray = new int[5]; this is an int array named myArray and can hold 5 int objects. so here is the model Object arrayName = new Object[arraySize]; Note: the objects are stored in number order and if you have five slots, the first slot is at 0 and the last is 4. It does Not start at 1. To store a object in the array (from the example above) myArray[0] = q; where q is an int To get the length of an array, use: myArray.length this will return 5 for my example. the access an object it simply: myArray[0].methodName(); Of course, change the number to get the different objects stored in the array. So to recap...
|
|
|
|
|
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Why Java RDBMS? | Iphone | Programming tutorials | 1 | 04-Dec-2007 01:16 AM |
| Java JDBC Tutorials - Topics include Java, Database, JDBC, Driver, ODBC and more! | Anilrgowda | Graphic tutorials | 0 | 04-Sep-2007 01:02 AM |
| DJ Java Decompiler 3.9.9.91 | Spirit-X | Application Downloads | 0 | 14-Jul-2007 06:00 AM |
| The Javalog.txt file is created in the Windows\Java folder when Java logging is enabl | Anilrgowda | Microsoft windows vista error | 0 | 29-Jan-2007 10:09 AM |
| Interfaces in Java | Anilrgowda | Programming tutorials | 0 | 03-Jan-2007 10:29 PM |