Méthode Java String copyValueOf()
Exemple
Renvoie une chaîne qui représente certains caractères d'un tableau de caractères :
char[] myStr1 = {'H', 'e', 'l', 'l', 'o'};
String myStr2 = "";
myStr2 = myStr2.copyValueOf(myStr1, 0, 5);
System.out.println("Returned String: " + myStr2);
Définition et utilisation
La copyValueOf()
méthode renvoie un String
qui représente les caractères d'un tableau de caractères.
Cette méthode renvoie un nouveau String
tableau et y copie les caractères.
Syntaxe
public static String copyValueOf(char[] data, int offset, int count)
Valeurs des paramètres
Parameter | Description |
---|---|
data | A char array |
offset | An int value, representing the start
index of the char array |
count | An int value, representing the length
of the char array |
Détails techniques
Retour: | A String , représentant les caractères du tableau char |
---|---|
Lance : | StringIndexOutOfBoundsException - si offset est négatif ou hors de portée, ou si count est supérieur à la longueur du tableau de caractères, ou négatif |
❮ Méthodes de chaîne