How do you shorten system.out.println in java

what is the absolute shortest possible shortcut to calling System.out.println, which makes it callable via the shortest number of characters (e.g. print ())

+10
source share
10 answers
import static java.lang.System.out; 

And in your code:

 out.println("Foo"); 
+21
source
 public static void print(String s) { System.out.println(s); } 
+7
source

Through Eclipse just type syso and then Ctrl+space

+6
source

In the Netbeans sout field and press TAB

+5
source

Autohotkey.ahk:

 #!o:: Send System.out.println("");{LEFT 3} 

Then press WIN + ALT + O.

Unfortunately, autohotkey only supports win32 .: (

+3
source

The shortest way is to create a method with a short name. Something like:

 public static void out(Object o){ System.out.println(o.toString()); } 

Now you only need to call ("foobar"); to print something standard. The reason I used the object and the toString () method, for example, is displayed correctly.

+2
source

If this is for the purpose of registering / debugging the logic of your program? A challenge that never happens.

If you are not writing a console-driven application, refrain from using System.out and System.err directly.

If you need registration, use the registration framework (jul, log4j, jcl, avalon, slf4j, logback, etc.). They allow you to improve context-specific information, improved granularity and configuration at runtime.

0
source

To make it shortest, you can write another function and use it, but type syso and press CTRL + Space - the best way, I think. You should get used to using shortcuts when coding in JAVA;)

0
source

Here is a workable example of the answers on this page, as well as a related question . I'm not sure if any of these shortcuts are recommended for readable, reusable code.

 import static java.lang.System.out; // only for method of minichate&Tim Cooper import java.io.PrintWriter;// only for method of Stephan Paul public class PrintExample{ public static void main(String[] args){ out.println("Typing of 7 characters saved!"); p.pl("shortened System.out.println, 14 characters saved."); p.pl(77); // takes non-strings p.out(88); // also takes non-strings p.print("sorry, I only take strings!"); //p.print(99); compilation error, int cannot be converted to String PrintWriter pr = new PrintWriter(System.out, true); pr.println(33); // method of Stephan Paul } } class p{ // using generics (Java 5.0 onwards), by carlos_lm public static <T> void pl (T obj){ System.out.println(obj); } // method by Neji3971 & bakkal, seems to work for all objects public static void out(Object o){ System.out.println(o.toString()); } // method by Jesus Ramos & rup. Only accepts strings!! public static void print(String s) { System.out.println(s); } } 
0
source

Use PhaseExpress for free. You do not care

0
source

All Articles