Results 1 to 3 of 3
Thread: Array problem please help
- 12-15-2010, 01:31 AM #1
Member
- Join Date
- Nov 2010
- Posts
- 7
- Rep Power
- 0
Array problem please help
Hi I am trying to create an array say of size 3. What I want this array to hold is another array. So say I have array myArr with indexes 0,1,2 .. In each of these indexes I want there to be another array. Is this possible in java?
If so how would I create the first array
whatComesHere[] myArr = new whatComesHere[3];
thanks
- 12-15-2010, 02:10 AM #2
Member
- Join Date
- Dec 2010
- Location
- Nova Scotia, Canada
- Posts
- 2
- Rep Power
- 0
Hi,
I think what you're looking for is a two-dimensional array which is indeed possible in java.
Basically you can create a blank 2d array like so:
whatComesHere[][] myArr = new whatComesHere[3][3];
This would create in that array three arrays each with the capacity of three separate values. Also you can create 2d arrays like so:
whatComesHere [][] myArr = {{1,2,3},{4,5,6},{7,8,9}};
Hope that helped :)
- 12-15-2010, 01:38 PM #3
Senior Member
- Join Date
- Feb 2010
- Location
- Ljubljana, Slovenia
- Posts
- 470
- Rep Power
- 10
You can also create a so called ragged array, that doesn't have the same length in every row like this:
Java Code:int[][] array = new int[5][]; for(int i = 0; i < array.length; i++) { array[i] = new int[i+1]; }
Ever seen a dog chase its tail? Now that's an infinite loop.
Similar Threads
-
Problem with Array Use
By Mike90 in forum New To JavaReplies: 1Last Post: 06-02-2010, 03:45 PM -
array problem
By jabo in forum New To JavaReplies: 2Last Post: 03-31-2010, 10:54 AM -
Array problem
By c3jcarmy in forum New To JavaReplies: 11Last Post: 03-11-2010, 03:45 AM -
Array problem
By binarzt in forum New To JavaReplies: 5Last Post: 02-14-2010, 10:01 AM -
array problem
By oceansdepth in forum New To JavaReplies: 3Last Post: 04-05-2008, 03:25 AM
Bookmarks