mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-08-26 00:11:26 +07:00
IDEA-167088 Stream API migration: support joining with delimiter
This commit is contained in:
+19
@@ -0,0 +1,19 @@
|
||||
// "Replace with collect" "true"
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class Test {
|
||||
static String test(List<String> list) {
|
||||
String sb = "";
|
||||
if (!list.isEmpty()) {
|
||||
sb = list.stream().filter(s -> !s.isEmpty()).map(s -> String.valueOf(s.length())).collect(Collectors.joining("\""));
|
||||
}
|
||||
return sb.trim();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(test(Arrays.asList("abc", "", "xyz", "argh")));
|
||||
}
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
// "Replace with collect" "true"
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class Test {
|
||||
static String test(List<String> list) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
if (!list.isEmpty()) {
|
||||
for (String s : li<caret>st) {
|
||||
if (!s.isEmpty()) {
|
||||
if (sb.length() > 0) {
|
||||
sb.append('"');
|
||||
}
|
||||
sb.append(s.length());
|
||||
}
|
||||
}
|
||||
}
|
||||
return sb.toString().trim();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(test(Arrays.asList("abc", "", "xyz", "argh")));
|
||||
}
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
// "Replace with collect" "false"
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class Test {
|
||||
static String test(List<String> list) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
StringBuilder sb2 = new StringBuilder();
|
||||
if (!list.isEmpty()) {
|
||||
for (String s : li<caret>st) {
|
||||
if (!s.isEmpty()) {
|
||||
if (sb2.length() > 0) {
|
||||
sb.append('"');
|
||||
}
|
||||
sb.append(s.length());
|
||||
}
|
||||
}
|
||||
}
|
||||
return sb.toString().trim();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(test(Arrays.asList("abc", "", "xyz", "argh")));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user