• Post Reply Bookmark Topic Watch Topic
  • New Topic

Convert a String in an Array when a Camel Case letter appears and add each word in a List.  RSS feed

 
Kaique Marques
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Everybody, I need some help with a problem, I need to separate a String in Arrays when a Camelcase appears in the String and store each word in a List. For example:

completeName= "complete", "name"
everyboryLovesCar= "everybody", "loves", "car"

here is what I got by now, but it is just stopping when it found a Camel Case letter and does not back to store again.




 
Dave Tolls
Rancher
Posts: 2914
36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the else you are breaking, which exits the loop, so will not do any more words beyond the first one.

Can you write out (in words) what you expect the loop to do (ignoring your current code)?
Something like:
 
Kaique Marques
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, I expect that:
For each letter in the String
if found a downcase letter store this letters in an Array


else (if found a UpperCase letter), create a new element of the list


Some people recommended me use REGEX, but I searched it on internet but i did not found a way to apply that in my problem
 
S Fox
Greenhorn
Posts: 18
1
Eclipse IDE Firefox Browser Netscape
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it sounds to me like you want to tokenize each word in a camelcase and put it into an arraylist? Something like this? String Tokenizer the String.split method does use regex, i guess that's why people recommended it.
 
Winston Gutkowski
Bartender
Posts: 10573
65
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kaique Marques wrote:Some people recommended me use REGEX, but I searched it on internet but i did not found a way to apply that in my problem

It's a bit involved, because it means "looking ahead", but it can be done, viz:Of course, it will only work with English language words (ie, where "capital" letters are "A-Z").

HIH

Winston
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!