MCPcopy Index your code
hub / github.com/benfry/processing4 / printArray

Method printArray

core/src/processing/core/PApplet.java:3922–3995  ·  view source on GitHub ↗

The printArray() function writes array data to the text area of the Processing environment's console. A new line is put between each element of the array. This function can only print one dimensional arrays. Note that the console is relatively slow. It works well for occasional messages, but

(Object what)

Source from the content-addressed store, hash-verified

3920 * @see PApplet#println()
3921 */
3922 static public void printArray(Object what) {
3923 if (what == null) {
3924 // special case since this does fugly things on > 1.1
3925 System.out.println("null");
3926
3927 } else {
3928 String name = what.getClass().getName();
3929 if (name.charAt(0) == '[') {
3930 switch (name.charAt(1)) {
3931 case '[' ->
3932 // don't even mess with multidimensional arrays (case '[')
3933 // or anything else that's not int, float, boolean, char
3934 System.out.println(what);
3935 case 'L' -> {
3936 // print a 1D array of objects as individual elements
3937 Object[] poo = (Object[]) what;
3938 for (int i = 0; i < poo.length; i++) {
3939 if (poo[i] instanceof String) {
3940 System.out.println("[" + i + "] \"" + poo[i] + "\"");
3941 } else {
3942 System.out.println("[" + i + "] " + poo[i]);
3943 }
3944 }
3945 }
3946 case 'Z' -> { // boolean
3947 boolean[] zz = (boolean[]) what;
3948 for (int i = 0; i < zz.length; i++) {
3949 System.out.println("[" + i + "] " + zz[i]);
3950 }
3951 }
3952 case 'B' -> { // byte
3953 byte[] bb = (byte[]) what;
3954 for (int i = 0; i < bb.length; i++) {
3955 System.out.println("[" + i + "] " + bb[i]);
3956 }
3957 }
3958 case 'C' -> { // char
3959 char[] cc = (char[]) what;
3960 for (int i = 0; i < cc.length; i++) {
3961 System.out.println("[" + i + "] '" + cc[i] + "'");
3962 }
3963 }
3964 case 'I' -> { // int
3965 int[] ii = (int[]) what;
3966 for (int i = 0; i < ii.length; i++) {
3967 System.out.println("[" + i + "] " + ii[i]);
3968 }
3969 }
3970 case 'J' -> { // int
3971 long[] jj = (long[]) what;
3972 for (int i = 0; i < jj.length; i++) {
3973 System.out.println("[" + i + "] " + jj[i]);
3974 }
3975 }
3976 case 'F' -> { // float
3977 float[] ff = (float[]) what;
3978 for (int i = 0; i < ff.length; i++) {
3979 System.out.println("[" + i + "] " + ff[i]);

Callers 3

printlnMethod · 0.95
writeCSVMethod · 0.95
launchJavaMethod · 0.95

Calls 3

printlnMethod · 0.45
getNameMethod · 0.45
flushMethod · 0.45

Tested by

no test coverage detected