lol, i meant the harder way I guess not the best. Is there a way of telling where a period should be by using some type of regular expression or string method?
Also, is this the best way for capitalizing the first Character in a string?
String s = "im a non capitalized sentence!";
char c;
c = s.charAt(0);
Character.toUpperCase(c)
s = s.replaceFirst(s.charAt(0),c)
One more question, Say I have like 5 lines of text in a string
String s = "5 lines of text(pretend)"
and I want to reset this every time like s = ""
should I call System.gc() after I set s to another set of text(5 lines)?
String literals aren't affected by garbage collection, and anyway calling System.gc() isn't guaranteed to do anything
The only reason to use it is to hint the JVM that now would be a nice time to clear up memory before you start a resource intensive operation (either CPU or RAM), but otherwise it's pretty useless.
lol, i meant the harder way I guess not the best. Is there a way of telling where a period should be by using some type of regular expression or string method?
Also, is this the best way for capitalizing the first Character in a string?
String s = "im a non capitalized sentence!";
char c;
c = s.charAt(0);
Character.toUpperCase(c)
s = s.replaceFirst(s.charAt(0),c)
A more efficient way to capitalise your first character would be to turn your String into a char array, capitalise element 0 in that, and then turn it back into a String.
Saves a few string operations.
No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.