Articles on Trending Technologies

Technical articles with clear explanations and examples

Java String toCharArray() method example.

Sai Nath
Sai Nath
Updated on 11-Mar-2026 154 Views

The toCharArray() method of a String class converts this string to a character array.Exampleimport java.lang.*; public class StringDemo {    public static void main(String[] args) {       // converts String value to character array type value       String str = " Java was developed by James Gosling";       char retval[] = str.toCharArray();       // displays the converted value       System.out.println("Converted value to character array = ");       System.out.println(retval);    } }OutputConverted value to character array = Java was developed by James Gosling

Read More

How is down-casting possible in Java?

Syed Javed
Syed Javed
Updated on 11-Mar-2026 236 Views

Yes, a variable can be downcast to its lower range substitute by casting. It may lead to data loss although. See the example below −Examplepublic class Tester {      public static void main(String[] args) {       int a = 300;         byte b = (byte)a;         System.out.println(b);    }   }OutputIt will print output as −44

Read More

How to test String is null or empty?

V Jyothi
V Jyothi
Updated on 11-Mar-2026 624 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.Exampleimport 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

Read More

How to Split a String with Escaped Delimiters?

Sravani S
Sravani S
Updated on 11-Mar-2026 518 Views

The split(String regex) method of the String class splits this string around matches of the given regular expression.Examplepublic class Sample{    public static void main(String args[]){       String s = "|A|BB||CCC|||";       String[] words = s.split("\|");       for (String string : words) {          System.out.println(string);       }    } }OutputA BB CCC

Read More

Bootstrap 4 .border-danger class

Alex Onsman
Alex Onsman
Updated on 11-Mar-2026 371 Views

Use the border-danger class to set a red border to an element.Set the border-danger class to an element as if we include any other class −   Red Border Above, we have also set another class “new”, to style the element − .new {   width: 120px;   height: 120px;   margin: 20px; } You can try to run the following code to implement the border-danger class −Example       Bootstrap Example                             .new {       width: 120px;       height: 120px;       margin: 20px;      }         Rectangle with red border:   Red Border

Read More

Constructor overloading in Java

Sravani S
Sravani S
Updated on 11-Mar-2026 7K+ Views

Yes! Java supports constructor overloading. In constructor loading, we create multiple constructors with the same name but with different parameters types or with different no of parameters.Examplepublic class Tester {      private String message;      public Tester(){       message = "Hello World!";    }    public Tester(String message){       this.message = message;    }      public String getMessage(){       return message ;    }      public void setMessage(String message){       this.message = message;    }      public static void main(String[] args) {       Tester tester = new Tester();       System.out.println(tester.getMessage());           Tester tester1 = new Tester("Welcome");       System.out.println(tester1.getMessage());      } }   OutputHello World! Welcome

Read More

Java string case change sample code examples.

Abhinanda Shri
Abhinanda Shri
Updated on 11-Mar-2026 209 Views

You can change the cases using the toUpperCase() and toLowerCase() methods of the String class.Examplepublic 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

Read More

Data Conversion Using valueOf() In Java.

Priya Pallavi
Priya Pallavi
Updated on 11-Mar-2026 414 Views

Java String class provides several variants of valueOf() method. These accept various data types and convert them into String.Examplepublic 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

Read More

How to Convert Double to String to Double in Java?

V Jyothi
V Jyothi
Updated on 11-Mar-2026 415 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() methodExamplepublic 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

Read More

How to write Java program to add two matrices

Samual Sam
Samual Sam
Updated on 11-Mar-2026 6K+ Views

To add two matrices −Create an empty matrixAt each position in the new matrix, assign the sum of the values in the same position from the given two matrices i.e. if A[i][j] and B[i][j] are the two given matrices then, the value of c[i][j] should be A[i][j] + B[i][j]Examplepublic class AddingTwoMatrices{    public static void main(String args[]){       int a[][]={{1,2,3},{4,5,6},{7,8,9}};       int b[][]={{1,1,1},{1,1,1},{1,1,1}};       int c[][]=new int[3][3];       for(int i = 0;i

Read More
Showing 24761–24770 of 61,297 articles
Advertisements