Solved

Dimensional Array

Posted on 2006-10-28
4
139 Views
Last Modified: 2010-03-31
How to create sub array with different length?

[0] - > [0]
[1] -> [0] [1]
[2] -> [0] [1] [2]
[3] -> [0] [1] [2] [3]
0
Comment
Question by:heyhey84
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 5

Accepted Solution

by:
gkishoreji earned 21 total points
ID: 17827927
// initially define only one dimension
int[][] a = new int[4][];

for(int i = 0; i < 4; i++)
{
// when needed, initialize the second dimension with required number of elements
a[i] = new int[i+1];
}
0
 

Author Comment

by:heyhey84
ID: 17827971
After able created my sub array with different length
The initial one dimension array will be all null

if i want to insert a value

Insert value 1
[0] -> [value 1]
[1] -> null
[2] -> null
[3] -> null

Insert value 2
[0] -> [Value 2]
[1] -> [Value 1][]
[2] -> null
[3] -> null

How do i create this insertion of value? bigger value to be store on top
0
 

Author Comment

by:heyhey84
ID: 17828150
void insert(int n) {
          
          // i think this should create the correct size of array
        count = count + 1;
          a[count] = new int[count+1];
          
        // how to insert the value into the correct slot?                    
       
    }
0
 

Author Comment

by:heyhey84
ID: 17832206
thanks
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
arguments to jar 5 39
Glassfish admin console not working 1 56
Tagging and Merging on Branch 1 39
Setup GlassFish 4 34
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question