Class FastUUID

java.lang.Object
com.eatthepath.uuid.FastUUID

public class FastUUID
extends Object

A utility class for quickly and efficiently parsing UUID instances from strings and writing UUID instances as strings. The methods contained in this class are optimized for speed and to minimize garbage collection pressure. In benchmarks, parseUUID(CharSequence) is a little more than 14 times faster than UUID.fromString(String), and toString(UUID) is a little more than six times faster than UUID.toString() when compared to the implementations in Java 8 and older. Under Java 9 and newer, parseUUID(CharSequence) is about six times faster than the JDK implementation and toString(UUID) does not offer any performance enhancements (or regressions!).

Author:
Jon Chambers
  • Method Details

    • parseUUID

      public static UUID parseUUID​(CharSequence uuidSequence)
      Parses a UUID from the given character sequence. The character sequence must represent a UUID as described in UUID.toString().
      Parameters:
      uuidSequence - the character sequence from which to parse a UUID
      Returns:
      the UUID represented by the given character sequence
      Throws:
      IllegalArgumentException - if the given character sequence does not conform to the string representation as described in UUID.toString()
    • toString

      public static String toString​(UUID uuid)
      Returns a string representation of the given UUID. The returned string is formatted as described in UUID.toString().
      Parameters:
      uuid - the UUID to represent as a string
      Returns:
      a string representation of the given UUID