I want to know how to convert a 2 dimensional array to a 1 dimensional array. I have come up with some code but it does not seem to really work, can someone help me? Thank you. Public class TESTER1 {/ ** * @ Ultimate Argos * / Static String [] [] Data = New String [] [] {{"Dumm", "Dumor", "Stupid" }}; Public static zero main (string [] args) {convert data (data); } Public static zero conversion data (string [] [] data) {string [] toReturn = new string [data.length]; For {int i = 0; i & lt; data.lamp; i ++} {for (int j = 0; j and lt; 3; j ++) {toReturn [i] = data [i] [ J]; }} (String s: toReturn) {System.out.println (s); }}}
[edit] Thanks a lot Is it possible to convert each line in string to an index in the string, for example if we change the string [] [] (the code above), when I print the array [0] printing it Public Static String [] Flaton (String [edit] Dam, Dummer, Dumest [edit]
or add full lines at one time:
for (int i = 0; i Edit: On my answer, comments seem to mean what OP wanted (i.e. to represent it on any string, each of the 2D array Change the line): public static string [] rowsTestring (string [] [] data) {ArrayList & lt; String & gt; List = New Arrestist & lt; String & gt; (); For (int i = 0; i & lt; data. Lamps; i ++) {string line = erase.stosting (data [i]); List.add (line.string (1, row.length () - 1)); } Return List. Arrow (new string [0]); }
Comments
Post a Comment