Java output printing tool encapsulation and java tool Encapsulation
When I print the output in Java and view the field value, I feel that the System is written every time. out. after the official release of println, I had to delete them one by one, which was too troublesome. After some suggestions, I made a Java printing and output encapsulation class, just to record this tool class. Not to mention, post code
1 package com. dyf. utils; 2/** 3 * Description: encapsulation output printing, set the print switch 4 * @ author diy 5*6 */7 public class SysoUtils {8 9 private static final boolean DEBUG = true; // output switch 10 11/** 12 * Description: Used to debug the output, replacing syso tool class 13 * Note: static method, use the class name to call 14 * use this tool class, please pay attention to rewrite tostring (), if you need to define other output styles, please modify the value of the 15 * Switch DEBUG switch to determine whether to switch the output. 16 * @ param args Variable Parameter List 17 */18 public static void print (Object... args) {19 if (DEBUG) {20 for (Object arg: args) {21 System. out. println (arg); 22} 23 System. out. println (); 24} 25} 26 27/* 28 * Description: or if only the string type is printed, use the following 29 private static final boolean DEBUG = false; 30 31 public static void p (String s) {32 if (DEBUG) {33 System. out. println (s); 34} 35} 36 */37 38}