Sales +91 850-603-0022 . HR & Training +91-769-609-5145

Home » Uncategorized » Easier ways to handle arrays — plus a little string manipulation

Easier ways to handle arrays — plus a little string manipulation

Find the middle ground between primitive arrays and Vectors, and string manipulation methods that help suppress homesickness for Perl

Primitive arrays in Java are not very object-oriented. You can get around this shortcoming by using a Vector, but, as I’ll explain in more detail below, this is often overkill. The first tool I will introduce is a simple object-oriented wrapper for a primitive array. After discussing arrays, I will move on to the second tool, a pair of little string manipulation routines that I use for splitting and joining, and that have come in handy for me many times.

Dealing with arrays can be a hairy business. You want to use primitive arrays for fast access and low memory overhead, but you don’t always know how big an array has to be until it’s already populated. You can use a Vector, but doing so means that each primitive value must be wrapped in an object. For example, any int has to be wrapped in an Integer object. But don’t lose heart — there is a happy medium, and that is this month’s first tool.

Leave a Reply

Your email address will not be published. Required fields are marked *