Laurent Hinoul

“Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.” - John F. Woods

How to format a website URL in Java

Most people want uniformity in their database. That is not always easy when you let the user enter data. Website URLs can come in all sizes. But how should you create an exactly uniform URL?

First, you have to check if the url is valid and not null, else you return null:

Then inside, the match case, you have to delete the protocols and www. (You can add protocols to filter by yourself.):

complete code:

Unit tests

Leave a Reply