jwenting
duckman
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
no, there's no need.
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.
jwenting
duckman
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
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)
Ah, you want a harder way?
String theString = "Hello World";
String theNewString = ((new StringBuffer(theString)).append(".")).toString();
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.
String theString = "hello world";
char[] theArray = theString.toCharArray();
theArray[0] = Character.toUpperCase(theArray[0]);
String theOtherString = new String(theArray);
jwenting
duckman
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337