Java.lang.String.copyValueOf() Method



Description

The java.lang.String.copyValueOf(char[] data, int offset, int count) method returns a String that represents the character sequence in the array specified.

Declaration

Following is the declaration for java.lang.String.copyValueOf() method

public static String copyValueOf(char[] data, int offset, int count)

Parameters

  • data − This is the character array.

  • offset − This is the initial offset of the subarray.

  • count − This is the length of the subarray.

Return Value

This method returns a String that represents the character sequence in the array specified.

Exception

NA

Example

The following example shows the usage of java.lang.String.copyValueOf() method.

package com.tutorialspoint;

import java.lang.*;

public class StringDemo {

   public static void main(String[] args) {

      // character array
      char[] charArr = { 'C', 'O', 'M', 'P', 'I', 'L', 'E', ' ',
         'O', 'N', 'L', 'I', 'N', 'E' };

      /* returns a String that contains the characters of the character
         array with offset as 8 and length as 6 */
      String str = String.copyValueOf(charArr, 8, 6 );

      // prints the substring with length as 6 
      System.out.println(str);
   }
}

Let us compile and run the above program, this will produce the following result −

ONLINE
java_lang_string.htm
Advertisements
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy