Benefits of a Module in Java 9

raja
Updated on 26-Feb-2020 10:04:14

697 Views

An important feature introduced in Java 9 is Module. By using a module, we can divide the code into smaller components called modules. It means each module has its own responsibility and declare its dependency on other modules to work correctly.Below are the steps to create a modular project in Java 9:Initially, we can create a file named "module-info.java" and add to a package(module) for which it is created. For instance, if our package name is com.mycompany.mypackage then the file goes to the same package (src/com.mycompany.mypackage/module-info.java). We can create a module by declaring "exports" and "requires" expressions.If our modules require another module ... Read More

Check if a String Contains Another String Case Insensitively in Java

Alankritha Ammu
Updated on 26-Feb-2020 09:59:12

2K+ Views

One way to do it to convert both strings to lower or upper case using toLowerCase() or toUpperCase() methods and test.ExampleLive Demopublic class Sample {    public static void main(String args[]){       String str = "Hello how are you welcome to Tutorialspoint";       String test = "tutorialspoint";       Boolean bool = str.toLowerCase().contains(test.toLowerCase());       System.out.println(bool);    } }Outputtrue

Determine if a String Contains Another String in Java

Akshaya Akki
Updated on 26-Feb-2020 09:58:29

193 Views

The java.lang.String.contains() method returns true if and only if this string contains the specified sequence of char values.ExampleLive Demopublic class Sample {    public static void main(String args[]){       String str = "Hello how are you welcome to tutorialspoint";       String test = "tutorialspoint";       Boolean bool = str.contains(test);       System.out.println(bool);    } }Outputtrue

Test if a String Contains Specific Words in Java

Alankritha Ammu
Updated on 26-Feb-2020 09:56:55

3K+ Views

The java.lang.String.contains() method returns true if and only if this string contains the specified sequence of char values.ExampleLive Demopublic class Sample {    public static void main(String args[]){       String str = "Hello how are you welcome to tutorialspoint";       String test = "tutorialspoint";       Boolean bool = str.contains(test);       System.out.println(bool);    } }Outputtrue

Difference Between String valueOf and toString in Java

Nikitha N
Updated on 26-Feb-2020 09:56:04

2K+ Views

The toString() method of the String class returns itself a string.ExampleLive Demoimport java.io.*; public class Test {    public static void main(String args[]) {       String Str = new String("Welcome to Tutorialspoint.com");       System.out.print("Return Value :");       System.out.println(Str.toString());    } }OutputReturn Value :Welcome to Tutorialspoint.comThe value of method variants of the String class accepts different variables such as integer, float, boolean etc.. and converts them into String.ExampleLive Demopublic class Sample {    public static void main(String args[]){       int i = 200;       float f = 12.0f;       ... Read More

Data Conversion Using valueOf in Java

Priya Pallavi
Updated on 26-Feb-2020 09:53:23

344 Views

Java String class provides several variants of valueOf() method. These accept various data types and convert them into String.ExampleLive Demopublic class Sample {    public static void main(String args[]){       int i = 200;       float f = 12.0f;       char c = 's';       char[] ch = {'h', 'e', 'l', 'l', 'o'};       String data = String.valueOf(i);       System.out.println(String.valueOf(i));       System.out.println(String.valueOf(f));       System.out.println(String.valueOf(c));       System.out.println(String.valueOf(ch));    } }Output200 12.0 s hello

Convert Double to String and Back to Double in Java

V Jyothi
Updated on 26-Feb-2020 09:51:54

336 Views

Java lang package provides a Double class which has methods to convert Double to String and vice versa. You can convert a String to a double using the parseDouble() method and double to String using the toString() methodExampleLive Demopublic class StringDouble {    public static void main(String args[]){       Double data1 = 2.2;       String str = Double.toString(data1);       System.out.println(str);       Double data2 = Double.parseDouble(str);       System.out.println(data2);    } }Output2.2 2.2

Converting Strings to Numbers and Vice Versa in Java

Sravani S
Updated on 26-Feb-2020 09:51:01

2K+ Views

Java lang package provides Integer class which has methods to convert an integer to String and vice versa. You can convert a String to an integer using the parseInt() method and Integer to String using the toString() method.ExampleLive Demopublic class Sample {    public static void main(String args[]){       String str = "1212";       int num = Integer.parseInt(str);       System.out.println(num);       String st = Integer.toString(num);       System.out.println();    } }Output1212

Java String Case Change Sample Code Examples

Abhinanda Shri
Updated on 26-Feb-2020 09:49:50

150 Views

You can change the cases using the toUpperCase() and toLowerCase() methods of the String class.ExampleLive Demopublic class Sample {    public static void main(String args[]){       String str = "Hello how are you";       String strUpper = str.toUpperCase();       System.out.println("Lower to upper : "+strUpper);       String strLower = str.toLowerCase();       System.out.println("Upper to lower : "+strLower);    } }OutputLower to upper : HELLO HOW ARE YOU Upper to lower : hello how are you

Check If String is Empty in Java

Jai Janardhan
Updated on 26-Feb-2020 09:43:28

185 Views

We can verify whether the given string is empty using the isEmpty() method of the String class. This method returns true only if length() is 0.ExampleLive Demoimport java.lang.*; public class StringDemo {    public static void main(String[] args) {       String str = "tutorialspoint";       // prints length of string       System.out.println("length of string = " + str.length());       // checks if the string is empty or not       System.out.println("is this string empty? = " + str.isEmpty());    } }Outputlength of string = 14 is this string empty? = false

Advertisements