I'm using IntelliJ IDEA for debugging a program in Java, that has an intense use of double[][] matrixes. I would like to find a method for easily displaying these matrixes during debugging, not just like:
But more like an entire matrix, for example something like this
A visualization like this should be displayed in the debugger variable's window.
I've searched many ways, but when it seems straightforward to do something like this in Python with PyCharm, it doesn't seem easy with Java/IntelliJ IDEA. I've also tried to customize the Java type renderer, but with no success. How can I do this?
Please add this method in any of your class:
public static String get2DArrayPrint(int[][] matrix) {
String output = new String();
for (int i = 0; i < matrix.length; i++) {
for (int j = 0; j < matrix[i].length; j++) {
output = output + (matrix[i][j] + "\t");
}
output = output + "\n";
}
return output;
}
Now in debugger mode right click in your variable and select view as -> Create Option. It will open screen similar to this:
Now in debugger mode right click on your variable and select view as -> Your scheme name (please check the screenshot).
Once it's done, please right click on a variable in debugger mode and select 'View Text'. This scheme will be applied to all 2D arrays in the program without any additional efforts. I hope this will help.
For now I've found an useful workaround by using ejml library's DMatrixRMaj
type.
I simply use this personalized Java Type Renderer (section accessible by right-clicking on variable/Customize Data Views/Java Type Renderers )
Then I right click on the matrix and select view text . There is a straightforward version for arrays.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.