Results 1 to 5 of 5
- 11-22-2008, 03:14 PM #1
Member
- Join Date
- Nov 2008
- Posts
- 19
- Rep Power
- 0
-
I know of no simple methods that fit this bill. The only solution I can think of for simplifying the calling of a toString method on a 2-D array would be to create a wrapper class that held the 2-D array and create a toString override method that internally would use nested for-loops and a StringBuilder to build the String you desire.
- 11-22-2008, 07:06 PM #3
Fubaable's recommendation is good, but even without that you don't need nested loops. Just call Arrays.toString in a single loop.
dbJava Code:int[][] ints = {{1,2},{33,44},{555,666}}; for (int[] is : ints) { System.out.println(Arrays.toString(is)); }
-
Darryl's suggestion is a good one, but if you look at the code for Arrays.toString, you'll see that it uses a StringBuilder and a for-loop, and so Darryl's example still uses at its core nested for-loops.
OK, so I cheated a little on this post. ;)
- 11-25-2008, 04:50 PM #5
Member
- Join Date
- Nov 2008
- Posts
- 19
- Rep Power
- 0
Similar Threads
-
How to make Java see a string as html
By matpj in forum Java AppletsReplies: 4Last Post: 09-26-2008, 03:40 AM -
how do i make a string return a number?
By pjr5043 in forum New To JavaReplies: 6Last Post: 09-15-2008, 04:56 AM -
Simplest ApplicationWindow Example
By Java Tip in forum SWTReplies: 0Last Post: 07-02-2008, 08:12 PM -
make a variable name from a string?
By Kinnikinnick in forum New To JavaReplies: 3Last Post: 11-13-2007, 03:54 PM -
I can't seem to pass the value of a string variable into a string array
By mathias in forum Java AppletsReplies: 1Last Post: 08-03-2007, 10:52 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks