zoukankan      html  css  js  c++  java
  • JAVA-各种类型之间转换 parse() 与valueOf()

    类型互转
    1.各种类型转String
    2.String转Bytes
    3.数组转List
    4.进制转换
    5.


    parse 在 SimpleDateFormat 中是转换为Date类,其它的一些包装类都是转换为int/double等基本类

    valueOf 转换的是类 eg: Integer /Double/Float....


    import java.lang.reflect.Constructor;
    import java.lang.reflect.InvocationTargetException;
    import java.util.Arrays;
    import java.util.HashMap;
    import java.util.List;
    import java.util.Map;
    import java.util.Map.Entry;
    import java.util.Scanner;
    
    public class Main {
    	
    	public static void main(String[] args) throws Exception {
    		Integer a = 12;
    		
    		Integer [] aaa = new Integer[10];
    		for(int i = 0;i<10;i++)
    			aaa[i] = new Integer(i);//对象数组要一个一个new
    		System.out.println(Arrays.toString(aaa));//自己主动拆包 数组转String
    		System.out.println(Integer.toBinaryString(a));//String
    		System.out.println(Integer.toHexString(a));//String
    		String t = "23";
    		byte [] b = t.getBytes();
    		Integer aa = Integer.parseInt(t, 10);
    		System.out.println(aa);
    		List list = Arrays.asList(aaa);	
    		System.out.println(list);
    		aaa = (Integer [])list.toArray(new Integer[0]);
    		System.out.println(Arrays.toString(aaa));
    	}
    }
    /*
     * [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
     *1100
     *c
     *23
     *[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
     *[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
     */
    class Child extends Main {
    	
    }


  • 相关阅读:
    poj 3278 catch that cow
    POJ 1028 Web Navigation
    poj 2643 election
    hdu 1908 double queues
    hdu_2669 Romantic(扩展欧几里得)
    0/1背包 dp学习~6
    校验码
    最长上升子序列(LIS经典变型) dp学习~5
    LCS最长公共子序列~dp学习~4
    最长上升子序列(LIS) dp学习~3
  • 原文地址:https://www.cnblogs.com/lxjshuju/p/6800212.html
Copyright © 2011-2022 走看看