Le java.lang.string.join() La méthode concatène les éléments donnés avec le délimiteur et renvoie la chaîne concaténée. Notez que si un élément est nul, alors null est ajouté. rejoindre() La méthode est incluse dans la chaîne Java depuis JDK 1.8.
Il existe deux types de rejoindre() méthodes dans la chaîne Java.
Syntaxe:
chiffres romains 1-100
public static String join (CharSequence deli, CharSequence... ele) and public static String join (CharSequence deli, Iterable ele) Parameters: deli - delimiter to be attached with each element ele - string or char to be attached with delimiter Returns : string joined with delimiter.>
// Java program to demonstrate> // working of join() method> > class> Gfg1 {> >public> static> void> main(String args[])> >{> >// delimiter is '<' and elements are 'Four', 'Five', 'Six', 'Seven'> >String gfg1 = String.join(>' <'>,>'Four'>,>'Five'>,>'Six'>,>'Seven'>);> > >System.out.println(gfg1);> >}> }> |
tableaux Java
>
menu des paramètres du téléphone Android
>
Sortir:
Four// Java program to demonstrate // working of join() method class Gfg2 { public static void main(String args[]) { // delimiter is ' ' and elements are 'My', // 'name', 'is', 'Niraj', 'Pandey' String gfg2 = String.join(' ', 'My', 'name', 'is', 'Niraj', 'Pandey'); System.out.println(gfg2); } } Output: My name is Niraj Pandey// Java program to demonstrate // working of join() method class Gfg3 { public static void main(String args[]) { // delimiter is '->' et les éléments sont 'Wake up', // 'Eat', 'Play', 'Sleep', 'Wake up' String gfg3 = String.join('-> ', 'Réveil', 'Manger', 'Jouer', 'Dormir', 'Réveil'); System.out.println(gfg3); } } Sortie : Réveil-> Manger-> Jouer-> Dormir-> Réveiller>