how to print a sentence out in a string of camel case java

http‮‬s://www.lautturi.com
how to print a sentence out in a string of camel case java

To print a sentence in camel case in Java, you can split the sentence into words, capitalize the first letter of each word, and concatenate the words with no spaces.

Here is an example of how you can print a sentence in camel case in Java:

public class CamelCasePrinter {
    public static void main(String[] args) {
        String sentence = "this is a sentence";
        String[] words = sentence.split(" ");
        StringBuilder camelCase = new StringBuilder();
        for (String word : words) {
            camelCase.append(word.substring(0, 1).toUpperCase())
                     .append(word.substring(1));
        }
        System.out.println(camelCase.toString());
    }
}

In this example, the main method defines a string with a sentence and splits it into words using the split method of the String class. The split method takes a regular expression as an argument and returns an array of strings with the words of the sentence.

Then, the main method creates a StringBuilder object to build the camel case string and uses a loop to iterate over the words of the sentence. For each word, the loop capitalizes the first letter using the substring and toUpperCase methods of the String class and appends it to the StringBuilder object.

Finally, the main method prints the camel case string using the toString method of the StringBuilder object. This code will print the following output:

ThisIsASentence

Keep in mind that this is just one way to print a sentence in camel case in Java. You can use different techniques and data structures to achieve the same result, such as using a loop to iterate over the characters of the sentence or using the String.replaceAll method to replace spaces with an empty string.

Created Time:2017-11-01 20:42:58  Author:lautturi