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

Groovy endsWith()

class Example {
   static void main(String[] args) {
      String s = "HelloWorld";
		
      println(s.endsWith("ld"));
      println(s.endsWith("lo"));
      println("Hello".endsWith("lo"));
   } 
} 

Groovy eachMatch()

class Example {
   static void main(String[] args) {
      String s = "HelloWorld";
      
      s.eachMatch(".") {
         ch -> println ch
      }
   }
}

Groovy concat()

class Example {
   static void main(String[] args) {
      String s = "Hello ";
      s = s.concat("World");
      System.out.println(s);
   } 
}

Groovy CompareToIgnoreCase()

class Example { 
   static void main(String[] args) { 
      String str1 = "Hello World"; 
      String str2 = "HELLO WORLD"; 
      String str3 = "HELLO World World";
		
      System.out.println(str1.compareToIgnoreCase( str2 )); 
      System.out.println(str2.compareToIgnoreCase( str3 )); 
      System.out.println(str3.compareToIgnoreCase( str1 )); 
   } 
}

Groovy center()

class Example { 
   static void main(String[] args) { 
      String a = "HelloWorld"; 
      println(a.center(30)); 
   } 
}

Groovy String Length

class Example {
   static void main(String[] args) {
      String a = "Hello";
      println(a.length());
   } 
}

Groovy String Repetition

class Example { 
   static void main(String[] args) { 
      String a = "Hello"; 
		
      println("Hello"*3); 
      println(a*3); 
   } 
}

Groovy Concatenation of Strings

class Example {
   static void main(String[] args) {
      String a = "Hello";
      String b = "World";
		
      println("Hello" + "World");
      println(a + b);
   }
}

String Indexing

class Example { 
   static void main(String[] args) { 
      String sample = "Hello world"; 
      println(sample[4]); // Print the 5 character in the string
		
      //Print the 1st character in the string starting from the back 
      println(sample[-1]); 
      println(sample[1..2]);//Prints a string starting from Index 1 to 2 
      println(sample[4..2]);//Prints a string starting from Index 4 back to 2 
      
   } 
}

Groovy Strings

class Example { 
   static void main(String[] args) { 
      String a = 'Hello Single'; 
      String b = "Hello Double"; 
      String c = "'Hello Triple" + "Multiple lines'";
		
      println(a); 
      println(b); 
      println(c); 
   } 
}

Advertisements
Loading...

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