Print shortcut

These alternative ways help print to console faster and, thus, debug and other actions faster by shorter typing:

 

  • Use the import static statement:
import static java.lang.System.out;

To print, call:

out.println(something);

 

  • Another way is to write this method in whatever class you want to print something from:
static void say(Object o)
{
     System.out.println(o);
}

This acts like a proxy method to System.out.println(), which is no different at all from it, just a shorter name (you can also choose your own name of course).

You can now print by writing:

say(something);

 

  • If you need to use this method often, you can write it inside a new, preferably with a short name, class:
class I
{
     static void say(Object o)
     {
          System.out.println(o);
     }
}

 

Hope this will increase your productivity!

Please like & share:
READ  Enumerators