-
/*Java String Length ExampleThis example shows how to get a length of a given String object.*/
public class StringLengthExample
{
public static void main(String[] args)
{//declare the String objectString str = “Hello World”;
//length() method of String returns the length of a String.int length = str.length();System.out.println(“Length of a String is : “ + length);}}
/*Output of a program would be:Length of a String is : 11*/
-
/*Java Char Array To String ExampleThis Java char array to String example shows how to convert char array toString in Java.*/public class CharArrayToStringExample{public static void main(String args[]){//char arraychar[] charArray = new char[]{‘J’,‘a’,‘v’,‘a’};/** To convert char array to String in Java, use* String(Char[] ch) constructor of Java String class.*/String str = new String(charArray);System.out.println(“Char array converted to String: “ + str);}}/*Output of above given char array to String example would beChar array converted to String: Java*/