Many thanks! That definitely answers my question.

John

On Wed, Sep 2, 2026 at 1:41 PM Dan Smith <[email protected]> wrote:

> > On Sep 2, 2026, at 7:40 AM, John Bossons <[email protected]> wrote:
> >
> > Sorry, I should have made it clear that I was referring to fixed-length
> > small strings, such as country-specific postal codes.
>
> If you want to minimize the memory footprint of a fixed-length
> alphanumeric code, here’s a tool you can use today:
>
> value class Alphanum6 implements Comparable<Alphanum6> {
>         int bits;
>         public Alphanum6(String code) {
>             if (code.length() != 6) throw new IllegalArgumentException();
>             bits = Integer.parseUnsignedInt(code, 36);
>         }
>         public String code() { return Integer.toUnsignedString(bits,
> 36).toUpperCase(); }
>         public String toString() { return code(); }
>         public int compareTo(Alphanum6 that) { return
> Integer.compareUnsigned(this.bits, that.bits); }
> }
>
> Extra work would be needed to support additional characters, including
> spaces or variable lengths (encoded as trailing <nothing> characters). But
> something in the same spirit could work for a variety of different
> length-limited string types.
>
> How does performance compare to Strings? Really depends on how it gets
> used. That would be an interesting experiment for a real application.
>
> Tools like this may eventually find a home in the standard library, but
> for now we (as a community) are really in the experimental phase. It’s
> unclear what the most important tools will turn out to be.
>
>

-- 
Phone:  (416) 450-3584 (cell)

Reply via email to