Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

convert two-dimensional array to string

Tags:

I'm trying to convert a String[][] to a string for display in a GUI. Here's my code:

String[][] tableBornes = SearchPropertiesPlugin.FillBornesTable(); String table = tableBornes.toString(); 

Here's what it produces:

[[Ljava.lang.String;@19b8858

How can I get something more readable?

like image 278
Asma.O Avatar asked Mar 25 '13 15:03

Asma.O


People also ask

How do you print a 2D array as a string?

We can use the Arrays. toString() method to print string representation of each single-dimensional array in the given two-dimensional array.

How we can convert a multidimensional array to string without any loop?

Multidimensional PHP Array to String Maybe in case you need to convert a multidimensional array into a string, you may want to use the print_r() function. This is also called “array with keys”. By adding “true” as its second parameter, all the contents of the array will be cast into the string. <?

How we can convert a multidimensional array to string without any loop in PHP?

function convert_multi_array($array) { foreach($array as $value) { if(count($value) > 1) { $array = implode("~", $value); } $array = implode("&", $value); } print_r($array); } $arr = array(array("blue", "red", "green"), array("one", "three", "twenty")); convert_multi_array($arr);


1 Answers

try one line version

Arrays.deepToString(tableBornes); 

or multiline version

StringBuilder sb = new StringBuilder(); for(String[] s1 : tableBornes){     sb.append(Arrays.toString(s2)).append('\n'); } String s = sb.toString(); 
like image 97
Evgeniy Dorofeev Avatar answered Sep 17 '22 14:09

Evgeniy Dorofeev