Skip to content

Tag: string

Why can’t I use switch statement on a String?

Is this functionality going to be put into a later Java version? Can someone explain why I can’t do this, as in, the technical way Java’s switch statement works? Answer Switch statements with String cases have been implemented in Java SE 7, at least 16 years after they were first requested. A clea…

What is meant by immutable?

What exactly does immutable mean – that is, what are the consequences of an object being mutable or immutable? In particular, why are Java’s Strings immutable? My understanding is that the StringBuilder type is something like a mutable equivalent to String. When would I use StringBuilder rather th…

How to generate a random alpha-numeric string

I’ve been looking for a simple Java algorithm to generate a pseudo-random alpha-numeric string. In my situation it would be used as a unique session/key identifier that would “likely” be unique over 500K+ generation (my needs don’t really require anything much more sophisticated). Idea…