Curriculum
Course: Java Basic
Login

Curriculum

Java Basic

Java Home

0/1

Java Introduction

0/1

Java Get Started

0/1

Java Syntax

0/1

Java Comments

0/1

Java Type Casting

0/1

Java Operators

0/1

Java Booleans

0/1

Java Switch

0/1

Java Break / Continue

0/1

Java Errors and Exception

0/1
Text lesson

copyValueOf()

Example

Generate a String representing specific characters from a char array.

char[] myStr1 = {'H', 'e', 'l', 'l', 'o'};
String myStr2 = "";
myStr2 = myStr2.copyValueOf(myStr1, 0, 5);    
System.out.println("Returned String: " + myStr2);

Definition and Usage

The copyValueOf() method yields a String representing the characters contained within a char array.

This function creates a fresh String array and duplicates the characters into it.

Syntax

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

Parameter Values

Parameter

Description

data

A char array

offset

An integer value indicating the starting index of the character array.

count

An integer value representing the length of the character array.

Technical Details

returns

A string representing the characters of the character array.

Throws

StringIndexOutOfBoundsException occurs if the offset is negative or out of range, or if the count exceeds the length of the character array, or if it’s negative.