Re: Need help with 2D array

From: Bryan Boone (Bryan.Boone_at_sas.com)
Date: 05/17/04

  • Next message: Silvio Bierman: "Re: How to invalidate a session?"
    Date: Mon, 17 May 2004 14:28:44 -0400
    
    

    Mark McConnell wrote:

    > "Khanh Le" <lekhanh88@earthlink.net> wrote in message news:<2fhoc.16965$Hs1.845@newsread2.news.pas.earthlink.net>...
    >
    >>Would someone shows me the java syntax to create a 2D array of a calendar,
    >>where the rows represents months, such as: Jan, Feb... and columns represent
    >>days; assuming that there are 29 days in Feb? I don't know whether to
    >>declare this 2D array in String or int, since the months are string while
    >>days are int. Thanks
    >
    >
    > I don't think an array is the best approach. You could read about the
    > class java.util.Calendar at
    > http://java.sun.com/j2se/1.4.2/docs/api/
    > That will let you compute that 29 is the last day of Calendar.FEBRUARY
    > in 2004, 31 is the last day of Calendar.MARCH in 2003, etc.
    >
    > To look up an array of int's, starting from a String, you could use a
    > Hashtable. This is awkward, so I don't recommend it, but I'll show it
    > to you.
    >
    > import java.util.Hashtable;
    >
    > Hashtable h = new Hashtable();
    > int[] daysJan = new int[31];
    > for (int i = 0; i < 31; ++i) {
    > daysJan[i] = i+1;
    > }
    > h.put("January", daysJan);
    > // Do the same for the other months.
    > // Later...
    > String nameOfMonth = "January";
    > int[] daysOfMonth = (int[])h.get(nameOfMonth);
    > // daysOfMonth is now the int array {1,2,...,31}

    I implemented a TableModel backed by a Calendar object and it _greatly_
    facilitated the viewing of Date in a JTable. All I was left with was
    concentrating the data (that is, the method implentation of TableModel)
    and the View (JTable) was going to be taken care of.
    No layouts, no custom painting, no custom components, etc, no problem;)
    -Bryan


  • Next message: Silvio Bierman: "Re: How to invalidate a session?"

    Relevant Pages

    • (patch for Bash) regex conditional tests
      ... 'regex' are returned in array variable SUBMATCH. ... Skipping of positional parameters, array elements, string ... int dollarflag, zeropad, compareflag; ... SHELL_VAR *var; ...
      (comp.unix.shell)
    • Re: String of numbers into to array of numbers
      ... then read that string and have the string show the ... individual numbers as in an array. ... int arryCnt = 0; ... qStr= cStr.substring); ...
      (comp.lang.java.help)
    • Re: How to Return an array of strings in C (char**)
      ... int start=0; ... // to know the number of elements in the array ... The reason is that you fail to increment str. ... The you could have printed "here" before entering the main loop to see if you actually got there, then str + start to see where you go to in the string on each pass. ...
      (comp.lang.c)
    • Re: read keyboard input and storing in an array?
      ... When in a loop, how do I simply ... The data returned by 'br.readLine' would always be a String so I've stored ... simply convert it to an int as follows: ... you could copy 'myInt' to your array. ...
      (comp.lang.java.help)
    • interop for string[] array
      ... that a pointer is passed to the array and that the array even not is pinned. ... But when it comes to passing a string[] array through a struct, ... int cElements; ... call int32 NWCNameTranslate::ADsBuildVarArrayStr(string, int32, ...
      (microsoft.public.dotnet.framework.interop)