Java Articles

Page 5 of 450

How to test String is null or empty?

V Jyothi
V Jyothi
Updated on 11-Mar-2026 604 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 508 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

Java string case change sample code examples.

Abhinanda Shri
Abhinanda Shri
Updated on 11-Mar-2026 195 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 396 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 395 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

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

Java program to print the transpose of a matrix

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 2K+ Views

The transpose of a matrix is the one whose rows are columns of the original matrix, i.e. if A and B are two matrices such that the rows of the matrix B are the columns of the matrix A then Matrix B is said to be the transpose of Matrix A.To print the transpose of the given matrix −Create an empty matrix.Copy the contents of the original matrix to the new matrix such that elements in the [j][i] position of the original matrix should be copied to the [i][j] position of the new matrix.Print the new matrix.Examplepublic class TransposeSample{   ...

Read More

Java program to print the transpose of a matrix

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 2K+ Views

The transpose of a matrix is the one whose rows are columns of the original matrix, i.e. if A and B are two matrices such that the rows of the matrix B are the columns of the matrix A then Matrix B is said to be the transpose of Matrix A.To print the transpose of the given matrix −Create an empty matrix.Copy the contents of the original matrix to the new matrix such that elements in the [j][i] position of the original matrix should be copied to the [i][j] position of the new matrix.Print the new matrix.Examplepublic class TransposeSample{   ...

Read More

Java program to calculate mode in Java

Chandu yadav
Chandu yadav
Updated on 11-Mar-2026 16K+ Views

In statistics math, a mode is a value that occurs the highest numbers of time. For Example, assume a set of values 3, 5, 2, 7, 3. The mode of this value set is 3 as it appears more than any other number.Algorithm1.Take an integer set A of n values. 2.Count the occurrence of each integer value in A. 3.Display the value with the highest occurrence.Examplepublic class Mode {    static int mode(int a[], int n) {       int maxValue = 0, maxCount = 0, i, j;       for (i = 0; i < n; ...

Read More
Showing 41–50 of 4,495 articles
« Prev 1 3 4 5 6 7 450 Next »
Advertisements