Showing posts with label Number Formating. Show all posts
Showing posts with label Number Formating. Show all posts

Sunday, April 6, 2014

Most commonly used Utility Methods in Java




How to truncate decimal value to two digits

     double d = 3.34568;
     DecimalFormat f = new DecimalFormat("##.00");
    Output is : 3.34


    public static void main(String args[]){
        // Initialize and assign String[] array
        String[] arr = new String[]{"A","B"};
        // Convert String[] array to List<String>
        List<String> arrList = new ArrayList<String>(Arrays.asList(arr));
        System.out.println(arrList);
        // Convert List<String> to String[] array
        arr = arrList.toArray(new String[arrList.size()]);
        System.out.println(arr);
    }