Re: iterating through an array of String's



thufir wrote:
Right, thanks for explaining what the result was! What I actually wanted to do was:

public static String TWO_D_ARRAY = {

Variable names by convention begin with a lower-case letter and use camelCase for the rest.

You named this variable an array, but didn't declare it as one. This statement will never compile.

{ "00", "01", "02" },
{ "10", "11", "12" },
{ "20", "21", "22" }},

public static String[] data;

data = TWO_D_ARRAY(0); //grabs 00, 01, 02

Array notation uses square brackets, not parentheses. As written, your statement will not compile.

to just grab a single row. seems silly to me, but this was, essentially,

Why? It's perfectly sensible and quite useful.

a requirement of the lab (to grab a row without explicitly iterating).

I think it's rather arcane,

Not at all. Since Java doesn't support two-dimensional arrays, it makes perfect sense. String [] [] doesn't declare an array of Strings, it declares an array of String [].

but it makes me wonder if there's some similar "magical" technique for grabbing column.

Nope. And there's absolutely nothing "magical" about grabbing rows - you actually aren't grabbing rows, you are grabbing array elements.

--
Lew
.



Relevant Pages

  • GetFields not working on enum type (anymore)
    ... I have a method that takes a type that relates to an enum and then gets ... GetFields only ever returns a zero length array. ... public static string[] GetEnumDescriptions ... ReturnNames = Temp; ...
    (microsoft.public.dotnet.languages.csharp)
  • Text problem
    ... GetHeaderFromFiles to build up the array. ... LogHead test = new LogHead; ... public static string GetHeaderFromFile ... public static string getDateStart() ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Text problem
    ... That is to read a log file into an> array and provide methods to get a random line. ... > LogHead test = new LogHead; ... > public static string GetHeaderFromFile ... > public static string getDateStart() ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: byte[] to string conversion ...
    ... public static string ByteArrayToString(byte[] array) ... string str = null; ... ascii.GetChars(array, 0, array.Length, asciiChars, 0); ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Passing an array of structuresfrom a pointer?
    ... to only declare structs in headers and then define the ... the struct should be declared ... what if you have a simple array like this: ... In the header we would declare? ...
    (microsoft.public.vc.language)