0
Trasform a string from normal to camelcase
what's the best way to trasform "Hello World" into "HeLlO wOrLd" ? thanks🖤
4 Respuestas
+ 2
I guess you will need to work with char array. So you can go like this once you have a char array from the string
Assuming first char is supposed to be in upper case
let boolean upperCase = true
for each character in char array
if character is alphabetic
if upperCase
convert character to upper case
else
convert character to lower case
end if
let upperCase = NOT upperCase
end if
end for
You can get help from `Character` class. It has methods needed to work with characters
https://www.tutorialspoint.com/java/java_characters.htm
+ 1
"HeLlO wOrLd" is not camel case, it's more about case inversion. First char in upper case, second in lower case and so on.
"helloWorld" is camel case
"HelloWorld" is Pascal case
+ 1
Java String is immutable, you cannot transform it directly. You can use the StringBuilder class for that.
https://zetcode.com/java/stringbuilder/
If you just want to print out the letters, without saving the string, then you don't even need that.
Just loop through the letters, and depending on if the letter index is odd or even, print a lowercase or uppercase version of the character.
0
oh, i didn't knew that sorry ahahaha...
but how can i trasform only 1 character in the strong? using charAt()?