Grails Cookbook - A collection of tutorials and examples

Groovy print Examples

The Groovy print method is similar to Java's System.out.print method. This method prints a value to the current out variable which can either be the PrintWriter or the standard out. When coding a script, this usually used to display something on the screen. Here are some Examples.

Syntax

Here is the syntax of Groovy print method.

public void print(Object value)

The parameter value is sent to the out variable. This is usually used to display the value to the console when we code a script.

Groovy print Examples

Here is a simple example of how to use the print method.

class GroovyPrintExample {
   static void main(String[] args) {
      print "Hello World"
      print "World"
   }
}

Here is the output on the screen.

Hello World

Note that the print method does not break the line. Consider this example:
class GroovyPrintExample {
   static void main(String[] args) {
      print "A"
      print "B"
      print "C"
   }
}

The output are printed on a single line as shown below:

ABC


Other Groovy Tutorials