Error » Certification & Programming center Error !! » Programming tutorials » Arrays in Java

Programming tutorials All Knowledge Info and links to posted here

Post New Thread Reply
  Arrays in Java
LinkBack Thread Tools Display Modes
Old 21-Dec-2006, 02:00 AM   #1 (permalink)
Administrator
 
Anilrgowda's Avatar

Posts: 18,715
Join Date: Jan 2006
Rep Power: 10 Anilrgowda is on a distinguished road

IM:
Default Arrays in Java

This tutorial is geared toward java, but it applys to many programming languages.
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...
  1. An array holds a numerous amounts of objects
  2. An array holds one type of Object
  3. An array has a set amount of slots for objects
  4. Object arrayName = new Object[arraySize]; Creating an array.
  5. myArray[0] = q; Calling a specific slot
  6. myArray.length (array length)
Anilrgowda is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Reply With Quote
   


   
Post New Thread Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

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


All times are GMT -8. The time now is 09:49 AM.

Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0

DMCA Policy

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228