Tabnine Logo
String.join
Code IndexAdd Tabnine to your IDE (free)

How to use
join
method
in
java.lang.String

Best Java code snippets using java.lang.String.join (Showing top 20 results out of 16,119)

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);
}
java.langStringjoin

Popular methods of String

  • equals
  • length
    Returns the number of characters in this string.
  • substring
    Returns a string containing a subsequence of characters from this string. The returned string shares
  • startsWith
    Compares the specified string to this string, starting at the specified offset, to determine if the
  • format
    Returns a formatted string, using the supplied format and arguments, localized to the given locale.
  • split
    Splits this string using the supplied regularExpression. See Pattern#split(CharSequence,int) for an
  • trim
  • valueOf
    Creates a new string containing the specified characters in the character array. Modifying the chara
  • indexOf
  • endsWith
    Compares the specified string to this string to determine if the specified string is a suffix.
  • toLowerCase
    Converts this string to lower case, using the rules of locale.Most case mappings are unaffected by t
  • contains
    Determines if this String contains the sequence of characters in the CharSequence passed.
  • toLowerCase,
  • contains,
  • getBytes,
  • <init>,
  • equalsIgnoreCase,
  • replace,
  • isEmpty,
  • charAt,
  • hashCode,
  • lastIndexOf

Popular in Java

  • Finding current android device location
  • onCreateOptionsMenu (Activity)
  • notifyDataSetChanged (ArrayAdapter)
  • orElseThrow (Optional)
    Return the contained value, if present, otherwise throw an exception to be created by the provided s
  • GridLayout (java.awt)
    The GridLayout class is a layout manager that lays out a container's components in a rectangular gri
  • IOException (java.io)
    Signals a general, I/O-related error. Error details may be specified when calling the constructor, a
  • ResultSet (java.sql)
    An interface for an object which represents a database table entry, returned as the result of the qu
  • MessageFormat (java.text)
    Produces concatenated messages in language-neutral way. New code should probably use java.util.Forma
  • JComboBox (javax.swing)
  • Join (org.hibernate.mapping)
  • Top Sublime Text plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now