Java Trimming Methods | |
---|---|
Method | Function |
ArrayList.trimToSize | chops off the unused RAM (Random Access Memory) on ArrayList’s internal array by allocating a new array just the right size and copying the elements over, then discarding the old internal array to be garbage collected. |
Collection.toArray | Exports an array just the right size. Always provide it with a template array the right size and type e.g. |
String.trim | removes both leading and trailing whitespace (not just blanks, nul, \n, \t…all the chars in the range 0..0x20) and gives you a new substring of the orginal. trim is neatly implmented. If there is nothing to trim, it just gives you your original String back. If there is something to trim, it gives you a substring view of your original immutable String. It does not need to allocate a new internal char[] or copy over the meat characters. In other words trim is a fast operation. |
ST.condense | collapses multiple spaces to a single space and trims off both leading and trailing spaces (not whitespace). |
ST.countLeading | count how many of a leading character there are, e.g. how many spaces or '*'s. |
ST.countTrailing | counts how many of a trailing character there are, e.g. how many spaces or '*'s. |
ST.squish | removes all spaces (not whitespace), included embedded ones. |
ST.trimLeading | removes just leading whitespace. |
ST.trimTrailing | removes just trailing whitespace. |
This page is posted |
http://mindprod.com/jgloss/trimming.html | |
Optional Replicator mirror
|
J:\mindprod\jgloss\trimming.html | |
Please read the feedback from other visitors,
or send your own feedback about the site. Contact Roedy. Please feel free to link to this page without explicit permission. | ||
Canadian
Mind
Products
IP:[65.110.21.43] Your face IP:[3.147.46.174] |
| |
Feedback |
You are visitor number | |