DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Snprintf For Java

  • submit to reddit
        sprintf and snprintf where things I used to really missing from C. 

Here is a straight forward snprintf implementation.

    public static String snprintf( int size, String format, Object ... args ) {
        StringWriter writer = new StringWriter( size );
        PrintWriter out = new PrintWriter( writer );
        out.printf( format, args );
        return writer.toString();