本文整理了Java中java.lang.String.join()
方法的一些代码示例,展示了String.join()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。String.join()
方法的具体详情如下:
包路径:java.lang.String
类名称:String
方法名:join
暂无
代码示例来源:origin: stackoverflow.com
String s = String.join("\n"
, "It was the best of times, it was the worst of times,"
, "it was the age of wisdom, it was the age of foolishness,"
, "it was the epoch of belief, it was the epoch of incredulity,"
, "it was the season of Light, it was the season of Darkness,"
, "it was the spring of hope, it was the winter of despair,"
, "we had everything before us, we had nothing before us"
);
代码示例来源:origin: stackoverflow.com
String joinedString = String.join(" - ", "04", "05", "06"); // "04 - 05 - 06"
代码示例来源:origin: stackoverflow.com
//directly specifying the elements
String joined1 = String.join(",", "a", "b", "c");
//using arrays
String[] array = new String[] { "a", "b", "c" };
String joined2 = String.join(",", array);
//using iterables
List<String> list = Arrays.asList(array);
String joined3 = String.join(",", list);
代码示例来源:origin: stackoverflow.com
List<String> list = Arrays.asList("foo", "bar", "baz");
String joined = String.join(" and ", list); // "foo and bar and baz"
代码示例来源:origin: stackoverflow.com
List<String> strings = new LinkedList<>();
strings.add("Java");strings.add("is");
strings.add("cool");
String message = String.join(" ", strings);
//message returned is: "Java is cool"
代码示例来源:origin: prestodb/presto
private String toVarcharValue(Object value)
{
if (value instanceof Collection<?>) {
return "[" + String.join(", ", ((Collection<?>) value).stream().map(this::toVarcharValue).collect(toList())) + "]";
}
if (value instanceof Document) {
return ((Document) value).toJson();
}
return String.valueOf(value);
}
代码示例来源:origin: Netflix/zuul
String headerAsString(HttpHeaders headers, String headerName)
{
List<String> values = headers.getAll(headerName);
return (values.size() == 0) ? "-" : String.join(",", values);
}
}
代码示例来源:origin: prestodb/presto
public static ResourceGroupIdTemplate fromSegments(List<ResourceGroupNameTemplate> segments)
{
return new ResourceGroupIdTemplate(String.join(".", segments.stream().map(ResourceGroupNameTemplate::toString).collect(Collectors.toList())));
}
代码示例来源:origin: spring-projects/spring-framework
public static void write(CandidateComponentsMetadata metadata, OutputStream out) throws IOException {
Properties props = new Properties();
metadata.getItems().forEach(m -> props.put(m.getType(), String.join(",", m.getStereotypes())));
props.store(out, "");
}
代码示例来源:origin: spring-projects/spring-framework
private static Properties createProperties(String key, String stereotypes) {
Properties properties = new Properties();
properties.put(key, String.join(",", stereotypes));
return properties;
}
代码示例来源:origin: prestodb/presto
private ZipFunction(List<String> typeParameters)
{
super(new Signature("zip",
FunctionKind.SCALAR,
typeParameters.stream().map(Signature::typeVariable).collect(toImmutableList()),
ImmutableList.of(),
parseTypeSignature("array(row(" + join(",", typeParameters) + "))"),
typeParameters.stream().map(name -> "array(" + name + ")").map(TypeSignature::parseTypeSignature).collect(toImmutableList()),
false));
this.typeParameters = typeParameters;
}
代码示例来源:origin: google/guava
/**
* Returns a list of objects with the same hash code, of size 2^power, counting calls to equals,
* hashCode, and compareTo in counter.
*/
static List<CountsHashCodeAndEquals> createAdversarialInput(int power, CallsCounter counter) {
String str1 = "Aa";
String str2 = "BB";
assertEquals(str1.hashCode(), str2.hashCode());
List<String> haveSameHashes2 = Arrays.asList(str1, str2);
List<CountsHashCodeAndEquals> result =
Lists.newArrayList(
Lists.transform(
Lists.cartesianProduct(Collections.nCopies(power, haveSameHashes2)),
strs ->
new CountsHashCodeAndEquals(
String.join("", strs),
() -> counter.hashCode++,
() -> counter.equals++,
() -> counter.compareTo++)));
assertEquals(
result.get(0).delegateString.hashCode(),
result.get(result.size() - 1).delegateString.hashCode());
return result;
}
代码示例来源:origin: google/guava
/**
* Returns a list of objects with the same hash code, of size 2^power, counting calls to equals,
* hashCode, and compareTo in counter.
*/
static List<CountsHashCodeAndEquals> createAdversarialObjects(int power, CallsCounter counter) {
String str1 = "Aa";
String str2 = "BB";
assertEquals(str1.hashCode(), str2.hashCode());
List<String> haveSameHashes2 = Arrays.asList(str1, str2);
List<CountsHashCodeAndEquals> result =
Lists.newArrayList(
Lists.transform(
Lists.cartesianProduct(Collections.nCopies(power, haveSameHashes2)),
strs ->
new CountsHashCodeAndEquals(
String.join("", strs),
() -> counter.hashCode++,
() -> counter.equals++,
() -> counter.compareTo++)));
assertEquals(
result.get(0).delegateString.hashCode(),
result.get(result.size() - 1).delegateString.hashCode());
return result;
}
代码示例来源:origin: google/guava
/**
* Returns a list of objects with the same hash code, of size 2^power, counting calls to equals,
* hashCode, and compareTo in counter.
*/
static List<CountsHashCodeAndEquals> createAdversarialInput(int power, CallsCounter counter) {
String str1 = "Aa";
String str2 = "BB";
assertEquals(str1.hashCode(), str2.hashCode());
List<String> haveSameHashes2 = Arrays.asList(str1, str2);
List<CountsHashCodeAndEquals> result =
Lists.newArrayList(
Lists.transform(
Lists.cartesianProduct(Collections.nCopies(power, haveSameHashes2)),
strs ->
new CountsHashCodeAndEquals(
String.join("", strs),
() -> counter.hashCode++,
() -> counter.equals++,
() -> counter.compareTo++)));
assertEquals(
result.get(0).delegateString.hashCode(),
result.get(result.size() - 1).delegateString.hashCode());
return result;
}
代码示例来源:origin: spring-projects/spring-framework
private void testWithQuotedParameters(String... mimeTypes) {
String s = String.join(",", mimeTypes);
List<MimeType> actual = MimeTypeUtils.parseMimeTypes(s);
assertEquals(mimeTypes.length, actual.size());
for (int i=0; i < mimeTypes.length; i++) {
assertEquals(mimeTypes[i], actual.get(i).toString());
}
}
代码示例来源:origin: spring-projects/spring-framework
private void verifyWrittenData(Flux<DataBuffer> writeResult) throws IOException {
StepVerifier.create(writeResult)
.consumeNextWith(stringConsumer("foo"))
.consumeNextWith(stringConsumer("bar"))
.consumeNextWith(stringConsumer("baz"))
.consumeNextWith(stringConsumer("qux"))
.expectComplete()
.verify(Duration.ofSeconds(3));
String result = String.join("", Files.readAllLines(tempFile));
assertEquals("foobarbazqux", result);
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void writeWritableByteChannelCancel() throws Exception {
DataBuffer foo = stringBuffer("foo");
DataBuffer bar = stringBuffer("bar");
Flux<DataBuffer> flux = Flux.just(foo, bar);
WritableByteChannel channel = Files.newByteChannel(tempFile, StandardOpenOption.WRITE);
Flux<DataBuffer> writeResult = DataBufferUtils.write(flux, channel);
StepVerifier.create(writeResult, 1)
.consumeNextWith(stringConsumer("foo"))
.thenCancel()
.verify(Duration.ofSeconds(5));
String result = String.join("", Files.readAllLines(tempFile));
assertEquals("foo", result);
channel.close();
flux.subscribe(DataBufferUtils::release);
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void writeWritableByteChannelErrorInFlux() throws Exception {
DataBuffer foo = stringBuffer("foo");
DataBuffer bar = stringBuffer("bar");
Flux<DataBuffer> flux = Flux.just(foo, bar).concatWith(Flux.error(new RuntimeException()));
WritableByteChannel channel = Files.newByteChannel(tempFile, StandardOpenOption.WRITE);
Flux<DataBuffer> writeResult = DataBufferUtils.write(flux, channel);
StepVerifier.create(writeResult)
.consumeNextWith(stringConsumer("foo"))
.consumeNextWith(stringConsumer("bar"))
.expectError()
.verify(Duration.ofSeconds(5));
String result = String.join("", Files.readAllLines(tempFile));
assertEquals("foobar", result);
channel.close();
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void writeAsynchronousFileChannelErrorInFlux() throws Exception {
DataBuffer foo = stringBuffer("foo");
DataBuffer bar = stringBuffer("bar");
Flux<DataBuffer> flux =
Flux.just(foo, bar).concatWith(Mono.error(new RuntimeException()));
AsynchronousFileChannel channel =
AsynchronousFileChannel.open(tempFile, StandardOpenOption.WRITE);
Flux<DataBuffer> writeResult = DataBufferUtils.write(flux, channel);
StepVerifier.create(writeResult)
.consumeNextWith(stringConsumer("foo"))
.consumeNextWith(stringConsumer("bar"))
.expectError(RuntimeException.class)
.verify();
String result = String.join("", Files.readAllLines(tempFile));
assertEquals("foobar", result);
channel.close();
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void writeAsynchronousFileChannelCanceled() throws Exception {
DataBuffer foo = stringBuffer("foo");
DataBuffer bar = stringBuffer("bar");
Flux<DataBuffer> flux = Flux.just(foo, bar);
AsynchronousFileChannel channel =
AsynchronousFileChannel.open(tempFile, StandardOpenOption.WRITE);
Flux<DataBuffer> writeResult = DataBufferUtils.write(flux, channel);
StepVerifier.create(writeResult, 1)
.consumeNextWith(stringConsumer("foo"))
.thenCancel()
.verify();
String result = String.join("", Files.readAllLines(tempFile));
assertEquals("foo", result);
channel.close();
flux.subscribe(DataBufferUtils::release);
}
内容来源于网络,如有侵权,请联系作者删除!