の java.lang.string.join() このメソッドは、指定された要素を区切り文字で連結し、連結された文字列を返します。要素が null の場合は、null が追加されることに注意してください。 参加する() JDK 1.8 以降、メソッドは Java 文字列に含まれています。
2種類あります 参加する() Java文字列のメソッド。
構文:
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);> > }> }> |
>
>
出力:
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 '->'、要素は 'Wake up', // 'Eat', 'Play', 'Sleep', 'Wake up' String gfg3 = String.join('-> '、'起きる'、'食べる'、'遊ぶ'、'寝る'、'起きる'); System.out.println(gfg3); 出力: 起きる -> 食べる -> 遊ぶ -> 寝る -> 起きる>>