Java中字符类型转换

来源:互联网 发布:java线程池原理 面试 编辑:程序博客网 时间:2024/06/05 17:50

Java中类型转为有两种方式,一种是parse()方法,一种是new 方法

String 转为intpublic static int StringToInt(String word){        int i = Integer.parseInt(word);        int i1= new Integer(word);// 第二种方法        return i;    }String 转为floatpublic static float StringToFloat(String word){        float f = Float.parseFloat(word);        float f1 =new Float(word);        return f;    }float转为string// boolean float double 转String 都是如此public static String FloatToString(float f){        String str = String.valueOf(f);        return str;    }/**     * 控制台读取文件     * @throws Exception     */    public static void readfilebyScanner() throws Exception{        Scanner sc = new Scanner(new File("test.txt"));        while(sc.hasNextLine()){            System.out.println(sc.nextLine());        }    }    /**     * 获取程序运行时对象     * @throws Exception      */    public static void runtime() throws Exception{        Runtime rt= Runtime.getRuntime();        System.out.println(rt.availableProcessors());//处理器数量        rt.freeMemory();        rt.totalMemory();        rt.maxMemory();        rt.exec("");//启动Windows系统的程序    }public static void Calendar1(){        Calendar cl =Calendar.getInstance();        Date date = cl.getTime();        cl.setTime(date);        cl.set(1,1);//设置时间        //TimeZone 获取时区    }
0 0
原创粉丝点击