Multi-dimensional array with nested loop not displaying correctly

Sembrano

I have a multidimentional array that is for a JTable. But it is not displaying the data correctly in the JTable its displaying like this from up to down on each row :

nidRbc  nidRbc  nidRbc  nidRbc  nidRbc  nidRbc  nidRbc  nidRbc  nidRbc
INTEGER INTEGER INTEGER INTEGER INTEGER INTEGER INTEGER INTEGER INTEGER
RBC identity    RBC identity    RBC identity    RBC identity    RBC identity    RBC identity    RBC identity    RBC identity    RBC identity
1   1   1   1   1   1   1   1   1
1   1   1   1   1   1   1   1   1
1   1   1   1   1   1   1   1   1
0   0   0   0   0   0   0   0   0
NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL
0:16382 0:16382 0:16382 0:16382 0:16382 0:16382 0:16382 0:16382 0:16382
maxRouteLength  maxRouteLength  maxRouteLength  maxRouteLength  maxRouteLength  maxRouteLength  maxRouteLength  maxRouteLength  maxRouteLength
NUMBER:3    NUMBER:3    NUMBER:3    NUMBER:3    NUMBER:3    NUMBER:3    NUMBER:3    NUMBER:3    NUMBER:3
Maximum length (km) of a locked route   Maximum length (km) of a locked route   Maximum length (km) of a locked route   Maximum length (km) of a locked route   Maximum length (km) of a locked route   Maximum length (km) of a locked route   Maximum length (km) of a locked route   Maximum length (km) of a locked route   Maximum length (km) of a locked route
1   1   1   1   1   1   1   1   1
1   1   1   1   1   1   1   1   1
2   2   2   2   2   2   2   2   2
0   0   0   0   0   0   0   0   0
50  50  50  50  50  50  50  50  50
###.### ###.### ###.### ###.### ###.### ###.### ###.### ###.### ###.###
minRouteLength  minRouteLength  minRouteLength  minRouteLength  minRouteLength  minRouteLength  minRouteLength  minRouteLength  minRouteLength
INTEGER INTEGER INTEGER INTEGER INTEGER INTEGER INTEGER INTEGER INTEGER
Minimum length (m) of a locked route    Minimum length (m) of a locked route    Minimum length (m) of a locked route    Minimum length (m) of a locked route    Minimum length (m) of a locked route    Minimum length (m) of a locked route    Minimum length (m) of a locked route    Minimum length (m) of a locked route    Minimum length (m) of a locked route
1   1   1   1   1   1   1   1   1
1   1   1   1   1   1   1   1   1
3   3   3   3   3   3   3   3   3
0   0   0   0   0   0   0   0   0
300 300 300 300 300 300 300 300 300
0:1000  0:1000  0:1000  0:1000  0:1000  0:1000  0:1000  0:1000  0:1000
maxMALength maxMALength maxMALength maxMALength maxMALength maxMALength maxMALength maxMALength maxMALength
NUMBER:3    NUMBER:3    NUMBER:3    NUMBER:3    NUMBER:3    NUMBER:3    NUMBER:3    NUMBER:3    NUMBER:3
Max length (km) for a Movement Authority    Max length (km) for a Movement Authority    Max length (km) for a Movement Authority    Max length (km) for a Movement Authority    Max length (km) for a Movement Authority    Max length (km) for a Movement Authority    Max length (km) for a Movement Authority    Max length (km) for a Movement Authority    Max length (km) for a Movement Authority
1   1   1   1   1   1   1   1   1
1   1   1   1   1   1   1   1   1
4   4   4   4   4   4   4   4   4
0   0   0   0   0   0   0   0   0
50  50  50  50  50  50  50  50  50
###.### ###.### ###.### ###.### ###.### ###.### ###.### ###.### ###.###
minMAExtension  minMAExtension  minMAExtension  minMAExtension  minMAExtension  minMAExtension  minMAExtension  minMAExtension  minMAExtension
INTEGER INTEGER INTEGER INTEGER INTEGER INTEGER INTEGER INTEGER INTEGER
Min length (m) to extend an existing MA Min length (m) to extend an existing MA Min length (m) to extend an existing MA Min length (m) to extend an existing MA Min length (m) to extend an existing MA Min length (m) to extend an existing MA Min length (m) to extend an existing MA Min length (m) to extend an existing MA Min length (m) to extend an existing MA
1   1   1   1   1   1   1   1   1
1   1   1   1   1   1   1   1   1
5   5   5   5   5   5   5   5   5
0   0   0   0   0   0   0   0   0
NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL
0:1000  0:1000  0:1000  0:1000  0:1000  0:1000  0:1000  0:1000  0:1000
minTrainSeparation  minTrainSeparation  minTrainSeparation  minTrainSeparation  minTrainSeparation  minTrainSeparation  minTrainSeparation  minTrainSeparation  minTrainSeparation
INTEGER INTEGER INTEGER INTEGER INTEGER INTEGER INTEGER INTEGER INTEGER
Min distance (m) between two trains Min distance (m) between two trains Min distance (m) between two trains Min distance (m) between two trains Min distance (m) between two trains Min distance (m) between two trains Min distance (m) between two trains Min distance (m) between two trains Min distance (m) between two trains
1   1   1   1   1   1   1   1   1
1   1   1   1   1   1   1   1   1
6   6   6   6   6   6   6   6   6
0   0   0   0   0   0   0   0   0
NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL
0:1000  0:1000  0:1000  0:1000  0:1000  0:1000  0:1000  0:1000  0:1000
siteOwner   siteOwner   siteOwner   siteOwner   siteOwner   siteOwner   siteOwner   siteOwner   siteOwner
STRING  STRING  STRING  STRING  STRING  STRING  STRING  STRING  STRING
Country and owner of line (for communication identities)    Country and owner of line (for communication identities)    Country and owner of line (for communication identities)    Country and owner of line (for communication identities)    Country and owner of line (for communication identities)    Country and owner of line (for communication identities)    Country and owner of line (for communication identities)    Country and owner of line (for communication identities)    Country and owner of line (for communication identities)
1   1   1   1   1   1   1   1   1
1   1   1   1   1   1   1   1   1
7   7   7   7   7   7   7   7   7
0   0   0   0   0   0   0   0   0
NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL
[^/]{1,5}/[^/]{1,5} [^/]{1,5}/[^/]{1,5} [^/]{1,5}/[^/]{1,5} [^/]{1,5}/[^/]{1,5} [^/]{1,5}/[^/]{1,5} [^/]{1,5}/[^/]{1,5} [^/]{1,5}/[^/]{1,5} [^/]{1,5}/[^/]{1,5} [^/]{1,5}/[^/]{1,5}
siteName    siteName    siteName    siteName    siteName    siteName    siteName    siteName    siteName
STRING  STRING  STRING  STRING  STRING  STRING  STRING  STRING  STRING
Name of line (for communication identities) Name of line (for communication identities) Name of line (for communication identities) Name of line (for communication identities) Name of line (for communication identities) Name of line (for communication identities) Name of line (for communication identities) Name of line (for communication identities) Name of line (for communication identities)
1   1   1   1   1   1   1   1   1
1   1   1   1   1   1   1   1   1
8   8   8   8   8   8   8   8   8
0   0   0   0   0   0   0   0   0
NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL
[^/]{1,15}  [^/]{1,15}  [^/]{1,15}  [^/]{1,15}  [^/]{1,15}  [^/]{1,15}  [^/]{1,15}  [^/]{1,15}  [^/]{1,15}
docNoSiteDataReport docNoSiteDataReport docNoSiteDataReport docNoSiteDataReport docNoSiteDataReport docNoSiteDataReport docNoSiteDataReport docNoSiteDataReport docNoSiteDataReport
STRING  STRING  STRING  STRING  STRING  STRING  STRING  STRING  STRING
Document number for site data report    Document number for site data report    Document number for site data report    Document number for site data report    Document number for site data report    Document number for site data report    Document number for site data report    Document number for site data report    Document number for site data report
1   1   1   1   1   1   1   1   1
1   1   1   1   1   1   1   1   1
9   9   9   9   9   9   9   9   9
0   0   0   0   0   0   0   0   0
NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL
NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL
docNoBaliseList docNoBaliseList docNoBaliseList docNoBaliseList docNoBaliseList docNoBaliseList docNoBaliseList docNoBaliseList docNoBaliseList
STRING  STRING  STRING  STRING  STRING  STRING  STRING  STRING  STRING
Document number for balise list Document number for balise list Document number for balise list Document number for balise list Document number for balise list Document number for balise list Document number for balise list Document number for balise list Document number for balise list
1   1   1   1   1   1   1   1   1
1   1   1   1   1   1   1   1   1
10  10  10  10  10  10  10  10  10
0   0   0   0   0   0   0   0   0
NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL
NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL
docNoGeographicalReport docNoGeographicalReport docNoGeographicalReport docNoGeographicalReport docNoGeographicalReport docNoGeographicalReport docNoGeographicalReport docNoGeographicalReport docNoGeographicalReport
STRING  STRING  STRING  STRING  STRING  STRING  STRING  STRING  STRING
Document number for geographical report Document number for geographical report Document number for geographical report Document number for geographical report Document number for geographical report Document number for geographical report Document number for geographical report Document number for geographical report Document number for geographical report
1   1   1   1   1   1   1   1   1
1   1   1   1   1   1   1   1   1
11  11  11  11  11  11  11  11  11
0   0   0   0   0   0   0   0   0
NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL
NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL
nidC    nidC    nidC    nidC    nidC    nidC    nidC    nidC    nidC
INTEGER INTEGER INTEGER INTEGER INTEGER INTEGER INTEGER INTEGER INTEGER
Country identity    Country identity    Country identity    Country identity    Country identity    Country identity    Country identity    Country identity    Country identity
0   0   0   0   0   0   0   0   0
1   1   1   1   1   1   1   1   1
12  12  12  12  12  12  12  12  12
0   0   0   0   0   0   0   0   0
NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL
1:1023  1:1023  1:1023  1:1023  1:1023  1:1023  1:1023  1:1023  1:1023

But I want it to display from left to right each data not from up to down

so should be like this :

nidRbc INTEGER RBC 1 1 1 0 NULL 0:16382
maxRouteLength NUMBER:3 Maximum 1 1 2 0 50 ###.###
minRouteLength INTEGER . ... .   etc etc..

This is my code right now :

// Create a list of node and compile the xpath expression
            NodeList nodeList = (NodeList) xPath.compile(expression).evaluate(
                    xmlDocument, XPathConstants.NODESET);

            System.out.println("nodelist length : " + nodeList.getLength());
            System.out.println("constant length : "
                    + constants.getParamColumns().length);

            // Create a new string for the array
            arr = new String[nodeList.getLength()][constants.getParamColumns().length];

            // Loop through the list and save the data in a string array.
            for (int i = 0; i < nodeList.getLength(); i++) {
                for (int j = 0; j < constants.getParamColumns().length; j++) {

                    System.out.println("content : "
                            + nodeList.item(i).getTextContent());
                    arr[i][j] = nodeList.item(i).getTextContent();
                    // System.out.println("Param : " + Arrays.toString(arr));

                }
            }
Sembrano

This is the solution :

for (int i = 0; i < nodeList.getLength()
                    / constants.getParamColumns().length; i++) {
                for (int j = 0; j < constants.getParamColumns().length; j++) {

                    arr[i][j] = nodeList.item(
                            j + (i * constants.getParamColumns().length))
                            .getTextContent();

                }
            }

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

assigning to multi-dimensional array

From Dev

Declare multi dimensional array

From Dev

Order array multi-dimensional

From Dev

Flattening a multi dimensional array

From Dev

Calculation and construction of two dimensional array with nested loop

From Dev

Sorting and displaying values systematically from a multi-dimensional PHP array

From Dev

Returning nested arrays from multi-dimensional array

From Dev

Displaying multi dimensional array with ReactJS

From Dev

Merging and looping multi dimensional array

From Dev

Skipping arrays in a multi-dimensional array during loop

From Dev

How can I loop over this multi dimensional array?

From Dev

Displaying nested array in twig

From Dev

PHP foreach loop on multi dimensional array

From Dev

How to parse this multi dimensional array

From Dev

PHP Nested foreach on multi dimensional array

From Dev

For-Loop to Generate Multi Dimensional Array

From Dev

Trouble making foreach loop for multi-dimensional array with StdClass Objects

From Dev

Parallelize nested for-loop on 3 dimensional array in R

From Dev

foreach loop inside multi-dimensional array

From Dev

Multi Dimensional array printing

From Dev

Loop through multi dimensional object

From Dev

Skipping arrays in a multi-dimensional array during loop

From Dev

Nested loop not working correctly

From Dev

PHP Help Building Multi-Dimensional Array in For Loop

From Dev

Two-dimensional Array Loop Not Displaying

From Dev

How to separate and assign data in a multi dimensional array via a loop - PHP

From Dev

Multi dimensional array in JQ

From Dev

Loop through each multi dimensional array and echo one array

From Dev

Multi Dimensional Array Construct

Related Related

HotTag

Archive