Java Snaps of the Day #1

adevedo's picture
No votes yet

This article contains a set of useful Java snaps collected from real Java source codes

Formatting a string using the logics provided by Formatter

How to implement binary search algorithm, extracted from the class org.apache.commons.lang.Entities from the apache commons lang library

Using DecimalFormat class for customized string representations for numbers (i.e. number length should be 4 digits, 0022...etc)

How to check if 2 files are with the same content, the sample uses Buffered Readers for loading the 2 files during the comparing process

How to replace the 1st occurrence of characters that matches a regular expression using the method String#replaceFirst

Using the method String#intern(), how to add a String object to the private String pool for better memory allocation for duplicate String objects

Escaping spacial characters logic for different formats (HTML, SQL..etc)


Hi Adevedo, really nice code snippets which will useful in real time projects. Thanks

Add new comment

This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Enter the characters shown in the image.
By submitting this form, you accept the Mollom privacy policy.