Formats a Date as a fifteen character long String made up of the Date's padded millisecond value. - Java java.util

Java examples for java.util:Date Format

Description

Formats a Date as a fifteen character long String made up of the Date's padded millisecond value.

Demo Code

/**// w ww  . j a  v  a 2  s.c om
     * Turns an array of bytes into a String representing each byte as an
     * unsigned hex number.
     * <p>
     * Method by Santeri Paavolainen, Helsinki Finland 1996<br>
     * (c) Santeri Paavolainen, Helsinki Finland 1996<br>
     * Distributed under LGPL.
     *
     * @param bytes
     *            an array of bytes to convert to a hex-string
     * @return generated hex string
     */
//package com.java2s;

import java.util.*;

public class Main {
    public static void main(String[] argv) throws Exception {
        Collection c = java.util.Arrays.asList("asdf", "java2s.com");
        String spilt = "java2s.com";
        System.out.println(collectionToString(c, spilt));
    }

    /**
     * Formats a Date as a fifteen character long String made up of the Date's
     * padded millisecond value.
     *
     * @return a Date encoded as a String.
     */

    @SuppressWarnings("unchecked")
    public static final String collectionToString(Collection c, String spilt) {
        if (c == null) {
            return null;
        }
        if (spilt == null) {
            return null;
        }
        String ret = "";
        ArrayList a = new ArrayList(c);
        try {
            for (int i = 0; i < a.size(); i++) {
                String t = (String) a.get(i);
                if (i == a.size() - 1) {
                    ret = ret + t;
                } else {
                    ret = ret + t + spilt;
                }
            }
            return ret;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
}

Related Tutorials