How to join character array to string with collectors joining in Java

1 Answer

0 votes
import java.util.stream.Collectors; 
import java.util.stream.Stream; 
 
public class MyClass {
    public static void main(String args[]) {
        char[] ch_arr = { 'j', 'a', 'v', 'a', ' ', 
                          'p', 'h', 'p', ' ', 
                          'c' }; 
  
        String s = Stream.of(ch_arr) 
                         .map(arr -> new String(arr)) 
                         .collect(Collectors.joining()); 
  
        System.out.println(s); 
    }
}
 
 
 
/*
run:
 
java php c
 
*/

 



answered Sep 30, 2019 by avibootz

Related questions

1 answer 194 views
1 answer 191 views
1 answer 143 views
1 answer 219 views
1 answer 125 views
...