java - how to group all of the characters of String into a 2d char array? -
i'd know how group of characters of string
char [][]
. suppose have
string m = "x b \n"+ "s d w \n"+ "d e f"
how can group characters of above string 2d char? method should group characters are, i.e.:
x b s d w d e f public void groupchars (string lines) { char [][]temp = new char [3][3]; }
one way of doing way [though have used string array]
public class test1 { public static void main(string args[]) { string s = "x b \n"+ "s d w \n"+ "d e f"; string[] splitparts = s.split(" "); string[][] newarray = new string[splitparts.length/3][3]; (int = 0, = 0; < newarray.length; a++) { newarray[a][0] = splitparts[i++]; newarray[a][1] = splitparts[i++]; newarray[a][2] = splitparts[i++]; } system.out.println(java.util.arrays.deeptostring(newarray)); } }
output:
[[x, a, b], [ s, d, w], [ d, e, f]]
Comments
Post a Comment