Two dimension array?

Show me the code for two dimension array in JSP!
Thanks in advance!

Hi,
I am new in Java but maybe I can help you:
Two-dimnsional arrays you can declare in following way:
String[][] someArray;
When you want to allocate space for new array you can do something like this:
someArray = new String[5][5];
All Arrays have a data variable called length, which you can inspect to find out how many elements there are in the array.
For multi-dimensional arrays, each dimension has a length property.
int[] [] a1 = {{ 0, 1, 2 },{ 3, 4, 5 }};
for (int i=0; i < a1.length; i++) {
for (int j=0; j < a1.length; j++) {
prt(i + "," + j + "=" + a1[i][j]);
Hope this is of help to you.
Mirkos

Similar Messages

  • Selecting one dimension of a two dimension array?

    hi, i want to select only one dimension of an array and put it into an arraylist (or casting the array verbatim into the arraylist)
    for example, here is an two dimension array:
    Object[][] data =
         {  { new Date(), "A", new Integer(1), Boolean.TRUE },
         { new Date(), "B", new Integer(2), Boolean.FALSE },
         { new Date(), "C", new Integer(9), Boolean.TRUE },
         { new Date(), "D", new Integer(4), Boolean.FALSE}
         };and i want to cast it into an arraylist, what i have in mind (a bit troublesome is the following:)
    ArrayList dataArray = new ArrayList();
    dataArray.add(data[0]);
    dataArray.add(data[1]);
    dataArray.add(data[2]);
    dataArray.add(data[3]);
    System.out.println(dataArray);when come upon the last System.out.println, i got some seemly useless addresses:
    [[Ljava.lang.Object;@f73c1, [Ljava.lang.Object;@789144, [Ljava.lang.Object;@1893efe, [Ljava.lang.Object;@186c6b2]
    how do you accomplish casting a two dimension array into an arraylist, but the second dimension of the arraylist is kept as Array of Objects? thanks alot!

    First, the strings that are printed out are the value of the hashcode for the specific object. That is the default value that is printed out for any object reference in a class that inherits the toString() method from the Object class. This is true for arrays. Your ArrayList contains array references in it..
    So, you are printing the object hashcodes for the arrays in your ArrayList, instead of the contents of those arrays. It would be better if you created ArrayLists, or even designed an object that stores your data, and stored those inside your ArrayList. ArrayList has an overwritten toString() method that will print the contents instead of the object hashcode, so an ArrayList containing ArrayLists would print your data the way you want. If you define your own class, you will need to provide a toString() method that prints the contents the way you want.
    PS, look at http://java.sun.com/j2se/1.5.0/docs/api/java/util/AbstractCollection.html#toString() for more information on the toString() method used by ArrayList.
    � {�                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Matrix in  java using  two dimension array

    hi!
    Everybody here's a problem I have cpould any body out there give nice piece of sourcr code for "matrix in java using two dimension array"I have to give a presentation how it works.Yes I'd appreciate as many example as possible
    If anybody can??
    Please help
    regards
    ardent

    nice piece of sourcr
    code for "matrix in java using two dimension
    n arraySure,
    int[][] matrix = new int[5][5];
    That declares a two-dimensional 5 by 5 array with integer elements. All elements are initially 0.
    For further information check you favourite Java textbook.

  • How to clear two dimension array and content in JTextArea

    hi all....
    i have a problem to clear the counter in JTextArea..currently i design a program to store all the student details in two dimensian array...when i click "RESET"button..it will only reset the textarea..but can not clear the actual content inside the array..and when i click "Print Button" again..it's supposed nothing to display..but it displayed the thing which i previously entered......
    so i think i need to clear the array...i use append to insert the text...,for this i also can not reset...
    which the code is shown below :
    txtArea.append(msg1);
    the coding for reset area as below :
    txtArea.setText("")
    Anyone can help me?????
    thks...

    How are you trying to reset the array?, you can just creat a new array.
    Noah

  • Two dimension string array in teststand

    Hello,
    I want to pass a two dimension string array from a labWindows dll into Teststand. My labwindows dll:
    #define NR_columns 12
    #define NR_rows  1200
    #define NR_hight   1024
    int__declspec(dllexport) __stdcall  sort( char pspec[NR_columns][NR_rows][NR_hight])
    The call of the dll in teststand looks like the attached picture in the doc file.
    and I got the error message which shows the attached second picture in the doc file
    what is the problem?
    regards
    samuel
    Attachments:
    Error1.doc ‏94 KB

    Hello Samuel,
    I'm not experienced in LabWindows but I think the reason for this Error is the dimension of FileGlobals.loadspec in TestStand. The Error Dialog displays for this String Array [0..11][0..1200]. That's an array of 12 and 1201 elements but function is expecting 12 and 1200 elements.
    I hope this helps.
    Kind regards
    C. Dietz
    Test Engineering
    digades GmbH
    www.digades.com

  • Variable number of two dimensional arrays into one big array

    I have a variable number of two dimensional arrays.
    The first dimension is variable, the second dimension is always 7.
    i.e.:
    Object[][] array0 = {
    {"tim", "sanchez", 34, 175.5, "bla", "blub", "[email protected]"},
    {"alice", "smith", 42, 160.0, "la", "bub", "[email protected]"},
    Object[][] array1 = {
    {"john", "sdfs", 34, 15.5, "a", "bl", "[email protected]"},
    {"joe", "smith", 42, 16.0, "a", "bub", "[email protected]"},
    Object[][] arrayi = ...I'm generating these arrays with a for-loop:
         for (int i = 0; i < filter.length; i++) {
              MyClass c = new MyClass(filter);
              //data = c.getData();
    Where "filter" is another array which is filled with information that tells "MyClass" how to fill the arrays.
    "getData()" gives back one of the i number of arrays.
    Now I just need to have everything in one big two dimensional array.
    i.e.:Object[][] arrayComplete = {
    {"tim", "sanchez", 34, 175.5, "bla", "blub", "[email protected]"},
    {"alice", "smith", 42, 160.0, "la", "bub", "[email protected]"},
    {"john", "sdfs", 34, 15.5, "a", "bl", "[email protected]"},
    {"joe", "smith", 42, 16.0, "a", "bub", "[email protected]"},
    Any idea on how to accomplish this? It's blowing my mind right now.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    Just brainstorming here:
    Why not put your actual data in a class and store that in a LinkedList (so you know the total number of elements for your multi-dimensional array). Then initalize your multi-dimensional array and populate it? Haven't tested the following, but thinking something along the lines of
    public class MyData {
         //data here
         public Object[] toArray() {
              //something similar to this
              return new Object[] = {"tim", "sanchez", 34, 175.5, "bla", "blub", "[email protected]"};
    LinkedList<MyData> data = new LinkedList<MyData>();
    data.add(mydata1);
    //however many times you need
    Object[][] arrayComplete = new Object[data.size()][7];
    for(int i = 0; i < data.size(); i++) {
         arrayComplete[i] = data.removeFirst().toArray();
    }Another option for knowing how many rows you would need might be using something like:
    int rows = 0;
    rows += array1.length;
    rows += array2.length;
    //etc...But is not entirely useful if you don't know how many variable arrays you have (although reflections might help if the name of the array variable is incremented systematically, someone told me earlier to avoid reflections since it could make debugging a LOT more difficult).
    Edited by: bogdana on Apr 1, 2010 10:38 AM

  • Set number of elements in a two dimensional array

    Hi,
    Does anyone know how to set the number of elements in a two dimensional array directly in teststand.
    To set a one dimsional array is simple:
    SetNumElements( locals.somearray,4)
    Is there a method to do this for a two dimensional array?
    Sean

    From the help file (TestStand 4.2.0):
    PropertyObject.SetNumElements
    SetNumElements Method
    Syntax
    PropertyObject.SetNumElements ( numElements, options = 0)
    Purpose
    Sets the number of elements of a single dimensional array.
    Remarks
    This method is only valid for single dimensional arrays. The elements in the array retain their values. Use the PropertyObjectType.ArrayDimensions property to set the number of elements in each dimension of a multi-dimensional array.
    Parameters
    numElements As Long
    [In] New number of elements for the array.
    options As Long
    [In] Pass 0 to specify the default behavior, or pass one or more PropertyOptions constants. Use the bitwise-OR operator to specify multiple options.
    This parameter has a default value of 0.
    So you could use, for example: Locals.MultidimensionalArray.Type.ArrayDimensions.SetBounds({1,0},{3,4}) to set an array to have three dimensions (1,2,3), each with five elements (0,1,2,3,4).

  • Is it possible to make a 2D array (or whatever-dimension) array like..

    Is it possible to make a 2D array (or whatever-dimension) array like this...
            collumn 1                   collumn 2
    Emulated Address   Real Memory address*
               (int)                            (int *)
    +----------------------+----------------------------+
    |            0                |              0xA0               | <-- row 1
    |            1                |              0xA1               | <-- row 2
    |            2                |              0xA2               | <-- row 3
    +----------------------+----------------------------+
    * A = Address.
    is it possible to make an array like that?
    if it is, please tell me how to do it...
    thanks.
    ... I'm trying to make an emulator to emulate the simplest memory.

    Given your other posts, I'm assuming you mean in C, right?
    If so, the answer is yes, but specifically how will depend on a needed clarification of your question.  What you present doesn't really need to be a 2 dimensional array, just one: that looks like a simple list of memory addresses, right?
    At the simplest you can declare an array with two dimensions `iny myarray[2][3];` but to make the table you put up there you'd only need `int *myarray[3];`
    If you also wanted space allocated somewhere that each element of that list pointed to, you could allocate them separately:
    int *myarray[3];
    myarray[0] = (int *) malloc(sizeof(int));
    myarray[1] = (int *) malloc(sizeof(int));
    myarray[2] = (int *) malloc(sizeof(int));
    Obviously with many entries this should be in a loop.  Perhaps not as obviously, why would you not just malloc a larger block of memory to start with?
    What is the end goal?
    EDIT: actually, upon rereading your question, the mallocs are probably irrelevant.  `int *myarray[3]` will get you the array you are looking for.  Just realize that until you point those pointers to memory you 'own' you shouldn't assign to or read from them.
    Last edited by Trilby (2013-04-19 10:06:31)

  • Cascade two Build Array functions - what happens?

    I found the the code shown in the attachment in a very complex VI that I am overhauling.  Would someone explain to me what is happening with the "cascaded" Build Array functions.
    I can see that the first Build Array function builds a 1D array of integers which passes to the second Build Array function which outputs a 2D array of integers but, since there is no Element or second Array input, I don't see how this works.
    This is part of a subVI that is not embedded in a loop.
     All the examples have at least two inputs.  With one input there is no Concatenate Inputs option. There is some implicit operation here that I do not understand.
    Would someone explain how this works? 
    Solved!
    Go to Solution.
    Attachments:
    Cascade two build array functions.PNG ‏7 KB

    You are taking a scalar value and creating a 1-D array with exactly 1 element.
    Then you are taking the 1-D array and building it into a 2-D array, with exactly 1 element.
    Since you can't concatenate something with nothing, the only logical mode for the Build Array would be to build it into an array of the next larger dimension.
    You could add a third one, then you'd have a 3-D array with exactly 1 element.  And so on.

  • Assigning two dimensional array to each other

    Hi All,
    I have two two-dimensional arrays and I want to assign one's second dimension's values as the other's second dimension's values in this way:
            int userCounter = 0;
            for (int userID : mostCommonUsers) {
                reducedTrainingVectorForSimilarity[userCounter] = trainingVectorForSimilarity[userID];
                userCounter++;
            }In the above code, I have an *"ArrayList<Integer> mostCommonUsers"*, and iterate through this. I'm using the values inside this array list, as a first dimension's index number of the *"trainingVectorForSimilarity"*, and assigning all the values in the second dimension to the left-hand-side array's second dimension. Both array has fixed length of second dimension. So, am I right by doing this, or I should make a for-loop to iterate over the individual values on the second dimensions of both arrays?
    Another similar question: In the below code, *"trainingVectorForSimilarity"* is an *"float[][]"*, so basically I assign all the second dimensions' values into a newly created array named *"trainingUserRatings"*. Again, I assumed that if the corresponding first dimesion's second dimension values will be assign without any iteration over each values.
    for (int i = 0; i < trainingVectorForSimilarity.length; i++) {
                float[] trainingUserRatings = trainingVectorForSimilarity;
    similarity[i] = calculateCosineSimilarity(testingVectorForSimilarity, trainingUserRatings);
    Am I right for both cases?                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    Here is the output for the code that you sent:
    [[1, 2, 3], [4, 5, 6]]
    [[1, 2, 3], [4, 5, 6]]
    [[1, 2, 3], [4, 5, 6]]
    [[1, 2, 3], [4, 5, 6]]
    [[1, 2, 3], [4, 999999, 6]]
    [[1, 2, 3], [4, 999999, 6]]
    [[1, 2, 3], [4, 999999, 6]]
    [[1, 2, 3], [4, 5, 6]]
    [null, [4, 999999, 6]]
    [null, [4, 999999, 6]]
    [[1, 2, 3], [4, 999999, 6]]
    [[1, 2, 3], [4, 5, 6]]I confused that even making an array copy still refers the same object but not a copy of that object. For example:
    float[][] trainingVectorForSimilarity is defined and initialized.
                float[] trainingUserRatings = new float[trainingVectorForSimilarity.length];
    trainingUserRatings = trainingVectorForSimilarity[i];
    is the same withfloat[] trainingUserRatings = new float[trainingVectorForSimilarity[i].length];
    System.arraycopy(trainingVectorForSimilarity[i], 0, trainingUserRatings, 0, trainingUserRatings.length);

  • How to convert Resulset to two dimenson array

    Hello,
    I have a Resulset, i want to store it in 2 dimenson array, but i can't.
    so I store the resulset in Vector:
    Vector row = new Vector();
    ResultSet rs = stmt.executeQuery(sql);
    ResultSetMetaData meta = rs.getMetaData();
    int colCount = meta.getColumnCount();
    while(rs.next()){
    String[] records = new String[colCount];
         for(int i=0; i<colCount; i++){
              records[i] = rs.getString(i+1);
         row.addElement(records);
    However i don't know to convert this Vector to two dimenson array.
    Can you help me:
    1. store the resulset to two dimenson array
    2. or convert the vector that store the resulset to two dimenson array

    The problem with storing the result into a two dimensional array directly is that you don't know the size required for the dimensions of the array, so you need to use something that is dynamic ( like a Vector, or a better use would be an ArrayList if you didn't need the container to be thread safe ).
    I might suggest something like this:
    ArrayList list = new ArrayList();
    ResultSet rs = stmt.executeQuery(sql);
    ResultSetMetaData meta = rs.getMetaData();
    int colCount = meta.getColumnCount();
    while(rs.next()){
    String[] records = new String[colCount];
    for(int i=0; i<colCount; i++){
    records[i] = rs.getString(i+1);
    row.add(records);
    String[][] resultArray = new String[ list.size() ][ colCount ];
    for ( int i = 0; i < list.size(); i++ ) {
        resultArray[ i ] = (String[])list.get( i );
    }

  • 2-dimension array

    hi,JDC people.
    i want to use a 2-dimension array, the length of the first dimension is know, the length of the second dimension varies. how could i define and add elements to the array? shall i use ArrayList?
    can anyone give some hint or simple example? thanks.

    In Java, you don't (strictly speaking) have a two-dimensional array, you have an array of arrays.
    If you know the length of the first array (dimension), you can declare it thusly:Object[][] objectsArray = new Object[2][]; // You've declared and initialised one 'dimension';You can then declare each of the second arrays (dimensions) in turn:objectsArray[0] = new Object[5];
    objectsArray[1] = new Object[936];
    // etc.You then refer to each Object in the array(s), like this:Object something = objectsArray[0][3]; // Fourth object in first array
    Object somethingElse = objectsArray[1][935]; // 936th object in second arrayHope this is helpful...
    Chris.

  • How to get number of rows and columns in a two dimensional array ?

    Hello,
    What would be the simplest way to get number of rows and columns in a two dimensional array represented as integers ?
    I'm looking for another solution as For...Each loop in case of large arrays.
    Regards,
    Petri

    Hi Petri,
    See a attached txt file for obtaining two arrays with upper and lower index values
    Regards
    Ray
    Regards
    Ray Farmer
    Attachments:
    Get2DArrayIndex.txt ‏2 KB

  • How can i declare 2 or more dimension array as function parameter???

    I am new to Objective-C and Cocoa. and now I have a problem.
    I want to send 2 dimension array to function but it cannot compile the error is "array type has incomplete element type" Please help me
    This is my Interface
    + (void) reValueInArray: (int[][] ) labelValue replaceValue: (int) oldValue withValue: (int) newValue;
    and one more question
    How can i get length of array
    1. array that declare as array at first (int a[5] for example)
    2. array that declare as pointer at first (int a* for example)
    Thank you Very much

    Satake wrote:
    a 2 dimension array is just an array of arrays correct?
    No. It isn't.
    so it'd be something like
    - (void)arrayManipulator:(NSArray *)aTwoDimensionArray;
    You're mixing metaphors. The original poster isn't using NSArray, but, rather, C arrays.
    + (void) reValueInArray: (int[][] ) labelValue replaceValue: (int) oldValue withValue: (int) newValue;
    In C, a multi-dimensional array is just one big, single-dimensioned array that uses fixed sizes for all but one of the component arrays to find a particular element. That means that you can't ever do something like:
    There are several workarounds.
    1) Use NSArray, as suggested in the first reply. That will solve this problem and lots more. With NSArray, you really an have arrays inside of arrays.
    2) Treat the array as just a plain old pointer in the function signature, then cast it back to the properly dimensioned array.
    3) Create a true array of arrays in C, using dynamic allocation. More trouble than it's worth.
    4...N) Other options that are probably more trouble than they're worth.

  • How to get Distinct Count of Products across two dimensions

    Hi,
    I have two dimensions, Item and Presentations. I need to get distinct count of products for IMD_Id + Merc_Pres_Id. IMD_Id is the lowest member in Item and Merc_Pres_Id is lowest in Presentation. My MDX query is given below but when I apply filters to
    slice it, it does not work and does not give right count. It always gives the count for all.
    /* Last Year Demand - Demand for 12 months back of selected months */
    With
    Member [Measures].[LYDemand]
    as
    Sum(
    Generate(
    EXISTING[All Date].[Fiscal Month Name].[Fiscal Month Name].Members,
    {parallelperiod([All Date].[Fiscal Month Name].[Fiscal Month Name], 12
    ,[All Date].[Fiscal Month Name].CurrentMember)}
    ,[Measures].[Proj Demand]
    /* Last to last Year Demand - Demand for 24 back of selected months */
    Member [Measures].[LLYDemand]
    as
    Sum(
    Generate(
    EXISTING[All Date].[Fiscal Month Name].[Fiscal Month Name].Members,
    {parallelperiod([All Date].[Fiscal Month Name].[Fiscal Month Name], 24
    ,[All Date].[Fiscal Month Name].CurrentMember)}
    ,[Measures].[Proj Demand]
    /* Current Year Active Products */
    Member [Measures].[CYCount]
    as
    CASE
    WHEN
    [Measures].[Proj Demand] > 0
    THEN
    DistinctCount(Existing(([All Items].[IMD Id].[IMD Id],[All Merchandise Presentations].[Merch
    Pres Key].[Merch Pres Key])))
    ELSE
    NULL
    END
    /* Last year Active Products */
    Member [Measures].[LYCount]
    as
    CASE
    WHEN
    [Measures].[LYDemand] > 0
    THEN
    DistinctCount(([All Items].[IMD Id].[IMD Id],[All Merchandise Presentations].[Merch Pres Key].[Merch Pres
    Key], [All Items].[Style Name].CurrentMember, (StrToMember('[All Date].[Fiscal Month Name].&[201401]',CONSTRAINED).Lag(12)
    : StrToMember('[All Date].[Fiscal Month Name].&[201411]',CONSTRAINED).Lag(12))))
    ELSE
    NULL
    END
    /* Last to last Year Active Products */
    Member [Measures].[LLYCount]
    as
    CASE
    WHEN
    [Measures].[LLYDemand] > 0
    THEN
    DistinctCount(([All Items].[IMD Id].[IMD Id],[All Merchandise Presentations].[Merch Pres Key].[Merch Pres
    Key], [All Items].[Style Name].CurrentMember, (StrToMember('[All Date].[Fiscal Month Name].&[201401]',CONSTRAINED).Lag(24)
    : StrToMember('[All Date].[Fiscal Month Name].&[201411]',CONSTRAINED).Lag(24))))
    ELSE NULL END
    SELECT
    [Measures].[CYCount], [Measures].[LYCount], [Measures].[LLYCount],
    [Measures].[Proj Demand],[Measures].[LYDemand],[Measures].[LLYDemand]
    ON
    COLUMNS,
    Non
    Empty([All Items].[Demand Center Name].[Demand Center Name], [All Items].[Style Name].[Style Name])
    ON ROWS
    FROM
    (SELECT (StrToSet('[All Items].[Style].[ALL]'))
    ON COLUMNS
    FROM
    (SELECT (StrToSet('[All Items].[Demand Center].[ALL]'))
    ON COLUMNS
    FROM
    (select (STRTOSET('[All Items].[Merch Group].&[MG-110]'))
    on Columns
    FROM
    (SELECT (StrToSet('[All Merchandise Presentations].[Merch Pres Chnl Dkey].&[MPC-1]'))
    ON COLUMNS
    From
    [FMI Forecasting]
    WHERE {strToMember('[All Date].[Fiscal Month
    Name].&[201401]',CONSTRAINED) :
    StrToMember('[All Date].[Fiscal Month Name].&[201411]',CONSTRAINED)}
    Requirements are as follows:
    1. Distinct Count should not include products where Proj Demand is 0, when I am using Filter function to remove products with 0 demand, query is really slow and execution time goes up from 35- 40 secs to 8-9 Minutes.
    2. When we apply filter (parameters) Distinct Count should be in the context of filters( which are mentioned in the select statement like Style, Demand Center and Merch Group). Currently after applying filters count does not change.
    Thanks for help.

    Hi Skd78,
    Thank you for your question. 
    I am trying to involve someone more familiar with this topic for a further look at this issue. Sometime delay might be expected from the job transferring. Your patience is greatly appreciated. 
    Thank you for your understanding and support.
    Regards,
    Charlie Liao
    TechNet Community Support

Maybe you are looking for

  • Help with HP 8610

    when I hit print My print goes to a file then into documents then pdf then print , lord how do I get it to just go to the printer I dont want it in a file

  • MXF audio not included with video

    In PP CS6, the audio of MXF files are not coming in.  The video is fine but there is no audio.  Is there a glitch or an update that fixes this problem?

  • ADF with JSF: How to execute a Sql statement created in a form

    Hello to every body, I'm working in JDeveloper 11.1.2.1.0, I have to do a development when the user can create a SQL statement and I have execute that before to do commit to the DB(Oracle DB). Example: The user create the next query: "+Select id_boss

  • Video does not play back - please help

    Hi everyone... Here are the specs: Premier Pro CS4 Windows XP SP3 Intel Core 2 Duo T9400 @ 2.53 Ghz 2.53 Ghz 2.90 GB 149 GB HD -  111 GB free space I am not able to play back any type of video, it will pixilated and freeze.  The audio plays fine.  I

  • Crystal 10 deployment problems to Windows 7

    Hi, I'm struggling with deployment to Windows 7 32bit and 64bit machines. Problem started with the release of new version of the software. Previous release was working on WIndows 7 32bit. New version has no changes in crystal functionality however it