Replicates the C# Convert.cs functionality in Java