{"id":1370,"date":"2022-03-03T07:42:51","date_gmt":"2022-03-03T07:42:51","guid":{"rendered":"https:\/\/mdr.foobrdigital.com\/?p=1370"},"modified":"2022-03-03T07:42:51","modified_gmt":"2022-03-03T07:42:51","slug":"capitalize-first-character-of-each-word","status":"publish","type":"post","link":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/2022\/03\/03\/capitalize-first-character-of-each-word\/","title":{"rendered":"Capitalize first character of each word"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Java program to make the first letter of a String capital<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>class Main {\n  public static void main(String&#91;] args) {\n\n    \/\/ create a string\n    String name = \"programiz\";\n\n    \/\/ create two substrings from name\n    \/\/ first substring contains first letter of name\n    \/\/ second substring contains remaining letters\n    String firstLetter = name.substring(0, 1);\n    String remainingLetters = name.substring(1, name.length());\n\n    \/\/ change the first letter to uppercase\n    firstLetter = firstLetter.toUpperCase();\n\n    \/\/ join the two substrings\n    name = firstLetter + remainingLetters;\n    System.out.println(\"Name: \" + name);\n\n  }\n}<\/code><\/pre>\n\n\n\n<p><strong>Output<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><samp>Name: Programiz <\/samp><\/code><\/pre>\n\n\n\n<p>In the example, we have converted the first letter of the string\u00a0<var>name<\/var>\u00a0to upper case.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Example 2: Convert every word of a String to uppercase<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>class Main {\n  public static void main(String&#91;] args) {\n\n    \/\/ create a string\n    String message = \"everyone loves java\";\n\n    \/\/ stores each characters to a char array\n    char&#91;] charArray = message.toCharArray();\n    boolean foundSpace = true;\n\n    for(int i = 0; i &lt; charArray.length; i++) {\n\n      \/\/ if the array element is a letter\n      if(Character.isLetter(charArray&#91;i])) {\n\n        \/\/ check space is present before the letter\n        if(foundSpace) {\n\n          \/\/ change the letter into uppercase\n          charArray&#91;i] = Character.toUpperCase(charArray&#91;i]);\n          foundSpace = false;\n        }\n      }\n\n      else {\n        \/\/ if the new character is not character\n        foundSpace = true;\n      }\n    }\n\n    \/\/ convert the char array to the string\n    message = String.valueOf(charArray);\n    System.out.println(\"Message: \" + message);\n  }\n}<\/code><\/pre>\n\n\n\n<p><strong>Output<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><samp>Message: Everyone Loves Java<\/samp><\/code><\/pre>\n\n\n\n<p>Here,<\/p>\n\n\n\n<ul><li>we have created a string named&nbsp;<var>message<\/var><\/li><li>we converted the string into a&nbsp;<code>char<\/code>&nbsp;array<\/li><li>we access every element of the&nbsp;<code>char<\/code>&nbsp;array<\/li><li>if the element is a white space, we convert the next element into uppercase<\/li><\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Java program to make the first letter of a String capital Output In the example, we have converted the first letter of the string\u00a0name\u00a0to upper case. Example 2: Convert every word of a String to uppercase Output Here, we have created a string named&nbsp;message we converted the string into a&nbsp;char&nbsp;array we access every element of [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[539],"tags":[],"_links":{"self":[{"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/posts\/1370"}],"collection":[{"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/comments?post=1370"}],"version-history":[{"count":0,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/posts\/1370\/revisions"}],"wp:attachment":[{"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/media?parent=1370"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/categories?post=1370"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/tags?post=1370"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}