long到number转换 ts_Java 类型转换 - osc_3fp081wq的个人空间 - OSCHINA - 中文开源技术交流社区...

类型转换

public class CharToIntExample {

public static void main(String args[]) {

char c = 'a';

char c2 = '1';

int a = c;

int b = c2;

System.out.println(a);

System.out.println(b);

int d=Character.getNumericValue(c2);

System.out.println(d);

}

}

import java.sql.Timestamp;

import java.text.SimpleDateFormat;

import java.util.Date;

public class DateToTimestampExample {

public static void main(String args[]) {

Date date = new Date();

Timestamp ts = new Timestamp(date.getTime());

System.out.println(ts);

SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

System.out.println(formatter.format(ts));

}

}

public class IntToStringExample1 {

public static void main(String args[]) {

int i = 200;

String s = String.format("%d", i);

System.out.println(s);

}

}

public class IntToStringExample2 {

public static void main(String args[]) {

int i = 200;

String s = Integer.toString(i);

System.out.println(i + 100);// 300 because + is binary plus operator

System.out.println(s + 100);// 200100 because + is string concatenation operator

}

}

import org.junit.Test;

public class LongToStringExample {

@Test

public void test1() {

long i = 9993939399L;

String s = String.valueOf(i);

System.out.println(s);

}

@Test

public void test2() {

long i = 9993939399L;

String s = Long.toString(i);

System.out.println(s);

}

}

import org.junit.Test;

public class ObjectToStringExample {

@Test

public void test() {

String s = "hello";

StringBuilder sb = new StringBuilder(s);

sb.reverse();

String rev = sb.toString();// converting StringBuilder to String

System.out.println("String is: " + s);

System.out.println("Reverse String is: " + rev);

}

}

import org.junit.Test;

public class StringToFloatExample {

@Test

public void test() {

String s = "23.6";

float f = Float.parseFloat(s);

System.out.println(f);

}

}

public class StringToIntegerExample {

public static void main(String args[]) {

String s = "hello";

int i = Integer.parseInt(s);

System.out.println(i); // NumberFormatException

}

}

public class StringToLongExample {

public static void main(String args[]) {

String s = "9990449935";

long l = Long.parseLong(s);

System.out.println(l);

}

}

public class TestStringToInt {

public static void main(String[] args) {

int a = Integer.parseInt("123");

Integer integer = Integer.valueOf(123);

System.out.println(a + 100);

System.out.println(integer + 100);

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值