• Post Reply Bookmark Topic Watch Topic
  • New Topic

Copying Lines to Columns in Multidimensional Arrays  RSS feed

 
Sabina Watson
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Basically, my problem is as follows, I have a string table with a variable number of lines and columns, and I'm looking for an efficient solution to copy the content of a line to a column and avoiding the ArrayOutOfBounds error. I realize there might be a simple solution out there, but somehow, I just can't grasp it.
 
Anayonkar Shivalkar
Bartender
Posts: 1558
5
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sabina Mw wrote:Basically, my problem is as follow, I have a string table with a variable number of lines and columns, and I'm looking for an efficient solution to copy the content of a line to a column and avoiding the ArrayOutOfBounds error. I realize there might be a simple solution out there, but somehow, I just can't grasp it.

Welcome to CodeRanch!

Few questions:
1) What is string table? Is it array of String arrays?
2) I assume by lines you meant rows.
3) How copying content of a row to a column would avoid any error?
4) By ArrayOutOfBounds error, I assume you meant ArrayIndexOutOfBounds exception.

Can you please post the code you are trying to work with?
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.
Why do you think you might run into the ArrayIndexOutOfBounds exception?
 
Sabina Watson
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1) What is string table? Is it array of String arrays?
Yes.

2) I assume by lines you meant rows.
Yes.

3) How copying content of a row to a column would avoid any error?
That was actually my concern in the first place.

4) By ArrayOutOfBounds error, I assume you meant ArrayIndexOutOfBounds exception.
And yes.
 
Sabina Watson
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anayonkar Shivalkar wrote:Can you please post the code you are trying to work with?


I'll just post an example of what I'm thinking right now, since I'm not quite fond of the way my code is turning out at the moment.

Consider this for a moment:



As I said, what I need, is to copy each character on a row to a column in the new table. The output would be something like this:

 
Campbell Ritchie
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no such thing as a multi-dimensional array; only arrays of arrays.
Get a pencil paper and eraser. The latter should be large because you will use it a lot Write down how you would do it, and get it into really simple terms. Then you will be able to convert it into code. Copying your array into another array (of a different size) might be one way to do it.
As for out of bounds Exceptions: if you write your for loops correctly, they will never cause such an Exception.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!