Is there a way to organize an array to look like a 2D array?

Hi,This may seem like a stupid question but is it possible to organize an array to look like a 2D array?
[118 byte] By [vopoa] at [2007-11-27 9:23:02]
# 1
arr[row * WIDTH + col] = 42;
pbrockway2a at 2007-7-12 22:17:52 > top of Java-index,Java Essentials,Java Programming...
# 2

> arr[row * WIDTH + col] = 42;

-sorry but I don't understand what this code does. Can you explain it to me how it can make my array look like a 2D array?

Here's my current array:

-I'm trying to make it look like a 2D array

String[] test = {

"3", "TaskTracker", "Add undo", "Active", "Unassigned",

"Feature", "1.0", "3 - Fix if time", "", "", "Gary",

"6-9-2006", "" ,

"2", "TaskTracker", "Icons need to be cleaned up", "Active",

"Unassigned", "Improvement", "1.0", "1 - Must Fix", "", "",

"Gary", "15-7-2006", "" ,

"1", "TaskTracker", "Clear doesn't clear the title", "Closed",

"Alex", "Bug", "1.0", "1 - Must Fix", "22-6-2006", "1 day",

"Sam", "3-6-2006", "..."

};

vopoa at 2007-7-12 22:17:52 > top of Java-index,Java Essentials,Java Programming...
# 3

what the f鷆k is going on? You already had this in a 2d array form previously vopo?

From this post

http://forum.java.sun.com/thread.jspa?threadID=5190517&messageID=9746166#9746166

you had:

private String[][] TEST_DATA = {

{ "3", "TaskTracker", "Add undo", "Active", "Unassigned",

"Feature", "1.0", "3 - Fix if time", "", "", "Gary",

"6-9-2006", "" },

{ "2", "TaskTracker", "Icons need to be cleaned up", "Active",

"Unassigned", "Improvement", "1.0", "1 - Must Fix", "", "",

"Gary", "15-7-2006", "" },

{ "1", "TaskTracker", "Clear doesn't clear the title", "Closed",

"Alex", "Bug", "1.0", "1 - Must Fix", "22-6-2006", "1 day",

"Sam", "3-6-2006", "..." } };

That is a 2D array. a terrible 2D array, but 2D nonetheless.

petes1234a at 2007-7-12 22:17:52 > top of Java-index,Java Essentials,Java Programming...
# 4
what game is this?
petes1234a at 2007-7-12 22:17:52 > top of Java-index,Java Essentials,Java Programming...
# 5

It's actually not a game.

It's like a test case for string manipulation my instructor gave me to test my code.

The reason I have a 1D array is b/c, "Arrays.sort " doesn't take a 2D array. So I have been for the past several hours trying to figure out a way to fix my problem, but I came to no solution.

vopoa at 2007-7-12 22:17:52 > top of Java-index,Java Essentials,Java Programming...
# 6

You have been given not only a solution, but it is the solution. You need to create a class to represent one of the rows of the array. That is the only way.

something like Task class

import java.util.GregorianCalendar;

class Task

{

private int number;

private String taskName;

private String functionality;

private String activity;

private String AssignedTo;

private String feature;

private double cost;

private String priority;

private String toBeAssigned1;

private String toBeAssigned2;

private String director;

private GregorianCalendar startDate;

private String toBeAssigned3;

public Task(int number, String taskName, String functionality,

String activity, String assignedTo, String feature,

double cost, String priority, String toBeAssigned1,

String toBeAssigned2, String director,

GregorianCalendar startDate, String toBeAssigned3)

{

this.number = number;

this.taskName = taskName;

this.functionality = functionality;

this.activity = activity;

AssignedTo = assignedTo;

this.feature = feature;

this.cost = cost;

this.priority = priority;

this.toBeAssigned1 = toBeAssigned1;

this.toBeAssigned2 = toBeAssigned2;

this.director = director;

this.startDate = startDate;

this.toBeAssigned3 = toBeAssigned3;

}

}

now make arrays out of objects of that class. THAT is what you are supposed to do.

The objects go here:

import java.util.Calendar;

import java.util.GregorianCalendar;

public class ArrayOfClass

{

private static final int TASK_COUNT = 3;

private Task[] tasks = new Task[TASK_COUNT];

public ArrayOfClass()

{

tasks[0] = new Task(3, "TaskTracker", "Add undo", "Active", "Unassigned",

"feature", 1.0, "3 - Fix if time", "", "", "Gary",

new GregorianCalendar(2006, Calendar.SEPTEMBER, 6), "");

tasks[1] = new Task(2, "TaskTracker", "Icons need to be cleaned up", "Active",

"Unassigned", "Improvenet", 1.0, "1 - Must Fix", "", "",

"Gary", new GregorianCalendar(2006, Calendar.OCTOBER, 15), "");

tasks[2] = new Task( 1, "TaskTracker", "Clear doesn't clear the title", "Closed",

"Alex", "Bug", 1.0, "1 - Must Fix", "22-6-2006", "1 day",

"Sam", new GregorianCalendar(2006, Calendar.APRIL, 6), "..." );

}

}

Lord, I hate spoon feeding.

Message was edited by:

petes1234

petes1234a at 2007-7-12 22:17:52 > top of Java-index,Java Essentials,Java Programming...
# 7
I never thought you can do it that way.Thanks
vopoa at 2007-7-12 22:17:52 > top of Java-index,Java Essentials,Java Programming...
# 8
> I never thought you can do it that way. In programming, you always have to think. We've been trying to nudge you in this direction, but you never picked up on it. You have to think OOP.Message was edited by: petes1234
petes1234a at 2007-7-12 22:17:52 > top of Java-index,Java Essentials,Java Programming...