You are here: Home / Topics / Simple string function example in Java

Simple string function example in Java

Filed under: Java on 2023-08-23 06:56:05

// Program to explain the following String function :
// String(char chars[ ], int startIndex, int numChars)

class  MString2
{
public static void main( String args[ ] )
{
 char ch[ ] = { 'J', 'A', 'V', 'A' };
 String s = new String( ch, 2, 2 );

 System.out.println( " String = " + s );

 // String s1 = 2015;   //  Error
 String s1 = "" + 2015;
 System.out.println( " String = " + s1 );
}
}


Output:

 String = VA
 String = 2015

 

About Author:
J
Java     View Profile
Hi, I am using MCQ Buddy. I love to share content on this website.