Error
The method collect(Collector<? super Integer,A,R>) in the type Stream<Integer> is not applicable for the arguments (Collector<CharSequence,capture#1-of ?,String>)
Error Type
Compile Time ( Java 8 )
Sample Code
Set<Integer> intSet = new HashSet<Integer>();
intSet.add(1);
intSet.add(2);
intSet.add(3);
intSet.add(4);
System.out.println(intSet.stream().collect((Collectors.joining())));
Cause
The method collect here expects the argument as Collector of Integer and not Collector of Strings.
Possible Resolution
If you would like to join elements, can keep Collection of Strings instead of Integer.
Set<String> strSet = new HashSet<String>();
strSet.add("1");
strSet.add("2");
strSet.add("3");
strSet.add("4");
System.out.println(strSet.stream().collect((Collectors.joining())));
The method collect(Collector<? super Integer,A,R>) in the type Stream<Integer> is not applicable for the arguments (Collector<CharSequence,capture#1-of ?,String>)
Error Type
Compile Time ( Java 8 )
Sample Code
Set<Integer> intSet = new HashSet<Integer>();
intSet.add(1);
intSet.add(2);
intSet.add(3);
intSet.add(4);
System.out.println(intSet.stream().collect((Collectors.joining())));
Cause
The method collect here expects the argument as Collector of Integer and not Collector of Strings.
Possible Resolution
If you would like to join elements, can keep Collection of Strings instead of Integer.
Set<String> strSet = new HashSet<String>();
strSet.add("1");
strSet.add("2");
strSet.add("3");
strSet.add("4");
System.out.println(strSet.stream().collect((Collectors.joining())));