About 11,200,000 results
Open links in new tab
  1. Add spaces between the characters of a string in Java?

    Iterate over the characters of the String and while storing in a new array/string you can append one space before appending each character. Something like this : StringBuilder result = new StringBuilder(); for(int i = 0 ; i < str.length(); i++) { result = result.append(str.charAt(i)); if(i == str.length()-1) break; result = result.append ...

  2. Adding whitespace in Java - Stack Overflow

    Mar 9, 2011 · I think you are talking about padding strings with spaces. One way to do this is with string format codes. For example, if you want to pad a string to a certain length with spaces, use something like this: String padded = String.format("%-20s", str); In a formatter, % introduces a format sequence.

  3. Spacing between two strings in Java - Stack Overflow

    Jul 9, 2014 · To add the two together with spacing, you can call: This will print person1.name, followed by a space (" "), followed by person2.age. Whatever is inside your " " will be printed, so you could print a : or a ; for example.

  4. Java Strings Concatenation - W3Schools

    The + operator can be used between strings to combine them. This is called concatenation: Note that we have added an empty text (" ") to create a space between firstName and lastName on print. You can also use the concat() method to concatenate two strings:

  5. How to add space between characters in Java

    In Java, you can add space between characters in a string using various methods. Here are a few common approaches: Using a Loop: You can iterate through the characters in the string and insert a space between each character.

  6. How To Add Space Between Two String In Java (Resolved)

    Jan 27, 2023 · In Java, you can use the concatenation operator (+) to add a space between two strings. For example: String str1 = "Hello"; String str2 = "World"; String str3 = str1 + " " + str2; System.out.println(str3); This will output the string "Hello World".

  7. How to add spaces between the characters of a string in Java

    To add spaces between the characters of a string in Java, you can use a loop to iterate through the characters of the original string and insert spaces between them. Here's a simple example: public static void main(String [] args) { String input = "Hello"; String spacedString = addSpaces(input);

  8. How to add space between two characters in Java

    To add space between two characters in a Java string, you can use various methods, depending on your specific requirements. Here are a few common approaches: Using String Concatenation: You can concatenate a space character ( " " ) between two …

  9. String Concatenation in Java - myCompiler

    If we want to add a space between the strings, we can do so by concatenating a space character: String str1 = "Hello"; String str2 = "World"; String str3 = str1 + " "+ str2; System.out.println(str3); // prints: Hello World. This will print "Hello World" to the console. We can also use the increment operator (+=) to join two strings:

  10. java - Adding space between characters - Stack Overflow

    Jun 22, 2012 · You can use the regular expression '..' to match each two characters and replace it with "$0 "to add the space: s = s.replaceAll("..", "$0 "); You may also want to trim the result to remove the extra space at the end.

  11. Some results have been removed
Refresh