Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

Execute Groovy Online

/* Hello World in Groovy */
class Example {
    static void main(String[] args)
    {
        def age = "Dog";
        age = 40;
        '''println("Addition : = " +(5.2.plus(4.4)));
        println("Addition : = " +(5.2.minus(4.4)));
        println("Addition : = " +(5.2.multiply(4.4)));
        println("Addition : = " +(5.2 / 4));
        println("age : = " + (++age));
        println("age : = " + (age++));
        println("age : = " + (age--));
        println("age : = " + (--age));
        println("Biggest Int = " + Integer.MAX_VALUE);
        println("Biggest Float = " + Float.MAX_VALUE);
        println("Biggest Int = " + Integer.MIN_VALUE);
        println("Biggest Float = " + Float.MAX_VALUE);
        println("Biggest Int = " + Double.MAX_VALUE);
         println("Biggest Int = " + Double.MIN_VALUE);'''
         def redomNum = 2.0;
    }
}

test

/* Hello World in Groovy */

//String text ="FROM LIFE OF LOAN:ANA1";
//String text ="FROM LIFE OF LOAN:ANA1 2020 23sd";
//String text=" 2010 PTP FASTPAY 1339.30 040 9" ;
String text = "FROM LIFE OF LOAN: LOAN MODIFIED EFFECTIVE 06/01/2010 PYMT; TERM=367 "
 REGEX_TO_ADD_SPACE_AFTER_SPECIAL_CHARACTER = ':' 

println(text.replaceAll(REGEX_TO_ADD_SPACE_AFTER_SPECIAL_CHARACTER,'\$0 ').trim())

Groovy this method for Properties

class Example { 
   int x = 100; 
	
   public int getX() { 
      this.x = 200; 
      return x; 
   } 
	
   static void main(String[] args) {

      Example ex = new Example(); 
      println(ex.getX());
   }
}

Groovy Instance methods

class Example { 
   int x; 
	
   public int getX() { 
      return x; 
   } 
	
   public void setX(int pX) { 
      x = pX; 
   } 
	
   static void main(String[] args) {
 
      Example ex = new Example(); 
      ex.setX(100); 
      println(ex.getX()); 
   } 
}

Groovy Method Return Values

class Example {
   static int sum(int a,int b = 5) {
      int c = a+b;
      return c;
   } 
	
   static void main(String[] args) {
      println(sum(6));
   } 
}

Groovy Default Parameters within Parameters

class Example {
   static void sum(int a,int b = 5) {
      int c = a+b;
      println(c);
   } 
	
   static void main(String[] args) {
      sum(6,6);
   } 
}

Groovy Default Parameters

class Example { 
   static void sum(int a,int b = 5) { 
      int c = a+b; 
      println(c); 
   } 
	
   static void main(String[] args) {
      sum(6); 
   } 
}

Groovy No Parameter

class Example {
   static def DisplayName() {
      println("This is how methods work in groovy");
      println("This is an example of a simple method");
   } 
	
   static void main(String[] args) {
      DisplayName();
   } 
}

Groovy No Parameter

class Example {
   static def DisplayName() {
      println("This is how methods work in groovy");
      println("This is an example of a simple method");
   } 
	
   static void main(String[] args) {
      DisplayName();
   } 
}

Groovy NodeBuilder

def nodeBuilder = new NodeBuilder() 

def studentlist = nodeBuilder.userlist {
   user(id: '1', studentname: 'John', Subject: 'Chemistry')
   user(id: '2', studentname: 'Joe', Subject: 'Maths')
   user(id: '3', studentname: 'Mark', Subject: 'Physics') 
} 

println(studentlist)

Previous 1 ... 5 6 7 8 9 10 11 ... 27 Next
Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.