예제가 포함된 Java 문자열 조인()

그만큼 java.lang.string.join() 메서드는 지정된 요소를 구분 기호로 연결하고 연결된 문자열을 반환합니다. 요소가 null이면 null이 추가됩니다. 가입하다() 메소드는 JDK 1.8부터 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);   } } 출력: 일어나기->먹기->놀이->잠자기->깨우기