1如何将字串 String 转换成整数 int?

  A. 有两个方法:

  1). int i = Integer.parseInt([String]); 或

  i = Integer.parseInt([String],[int radix]);

  2). int i = Integer.valueOf(my_str).intValue();

  注: 字串转成 Double, Float, Long 的方法大同小异.

  2 如何将整数 int 转换成字串 String ?

  A. 有叁种方法:

  1.) String s = String.valueOf(i);

  2.) String s = Integer.toString(i);

  3.) String s = "" + i;

  注: Double, Float, Long 转成字串的方法大同小异.

  Java数据类型转换 ynniebo [收藏]

  关键字 类型转换

  出处

  这是一个例子,说的是JAVA中数据数型的转换.供大家学习引

  package cn.com.lwkj.erts.reGISter;

  import java.sql.Date;

  public class TypeChange {

  public TypeChange() {

  }

  //change the string type to the int type

  public static int stringToInt(String intstr)

  {

  Integer integer;

  integer = Integer.valueOf(intstr);

  return integer.intValue();

  }

  //change int type to the string type

  public static String intToString(int value)

  {

  Integer integer = new Integer(value);

  return integer.toString();

  }

  //change the string type to the float type

  public static float stringToFloat(String floatstr)

  {

  Float floatee;

  floatee = Float.valueOf(floatstr);

  return floatee.floatValue();

  }

  //change the float type to the string type

  public static String floatToString(float value)

  {

  Float floatee = new Float(value);

  return floatee.toString();

  }

  //change the string type to the sqlDate type

  public static java.sql.Date stringToDate(String dateStr)

  {

  return java.sql.Date.valueOf(dateStr);

  }

  //change the sqlDate type to the string type

  public static String dateToString(java.sql.Date datee)

  {

  return datee.toString();

  }

  public static void main(String[] args)

  {

  java.sql.Date day ;

  day = TypeChange.stringToDate("2003-11-3");

  String strday = TypeChange.dateToString(day);

  System.out.println(strday);

  }

  }

  JAVA中常用数据类型转换函数

  虽然都能在JAVA API中找到,整理一下做个备份。

  string->byte

  Byte static byte parseByte(String s)

  byte->string

  Byte static String toString(byte b)

  char->string

  Character static String to String (char c)

  string->Short

  Short static Short parseShort(String s)

  Short->String

  Short static String toString(Short s)

  String->Integer

  Integer static int parseInt(String s)

  Integer->String

  Integer static String tostring(int i)

  String->Long

  Long static long parseLong(String s)

  Long->String

  Long static String toString(Long i)

  String->Float

  Float static float parseFloat(String s)

  Float->String

  Float static String toString(float f)

  String->Double

  Double static double parseDouble(String s)

  Double->String

  Double static String toString(Double d)

JAVA的整型与字符串相互转换的更多相关文章

  1. (转)JAVA的整型与字符串相互转换

    JAVA的整型与字符串相互转换1如何将字串 String 转换成整数 int? A. 有两个方法: 1). int i = Integer.parseInt([String]); 或         ...

  2. Java整型与字符串相互转换

    >>>>>>>>>>>>>>>>>>>> 1如何将字串 String 转换成整数 ...

  3. Java整型与字符串相互转换(转)

    1如何将字串 String 转换成整数 int? A. 有两个方法: 1). int i = Integer.parseInt([String]); 或 i = Integer.parseInt([S ...

  4. java数组与字符串相互转换、整型与字符串相互转换【详解】

      java 数组->字符串 1.char数组(字符数组)->字符串 可以通过:使用String.copyValueOf(charArray)函数实现.  举例: char[] arr={ ...

  5. Java:集合,对列表(List)中的数据(整型、字符串、日期等)进行排序(正序、倒序)的方法;字符串按照整型排序的方法

    1. 要求 对List列表中的数据进行排序(正序.倒序),列表中的数据包括:整型(Integer).字符串(String).日期(Date)等.对于字符串,要求允许对它按照整型进行排序. 2. 实现思 ...

  6. JAVA 长整型转换为IP地址的方法

    JAVA 长整型转换为IP地址的方法 代码例如以下: /** * 整型解析为IP地址 * @param num * @return */ public static String int2iP(Lon ...

  7. stringsteam使用之整型转字符串

    最近需要用到整型转字符串的操作,学习了stringstream一些皮毛. 首先需要包含头文件. #include<sstream> 然后用流操作的方式将值传递给stringstream对象 ...

  8. 深入理解Java的整型类型:如何实现2+2=5?

    先看下这段神奇的Java代码: public static void main(String[] args) throws Exception { doSomethingMagic(); System ...

  9. python学习3—数据类型之整型、字符串和布尔值

    python学习3-数据类型之整型.字符串和布尔值 数据类型 python3支持的数据类型共有6种: 1 Number 2 String 3 List 4 Tuple 5 Set 6 Dictiona ...

随机推荐

  1. Linux命令学习-mkdir

    1. [root@www tmp]# mkdir test    <=建立一名为 test 的新目录 2. [root@www tmp]# mkdir -p /opt/tmp/abc   < ...

  2. jenkins配置记录(1)--添加用户权限

    前一阵子在线上部署了一套jenkins环境,作为线上代码发布平台使用.部署记录:http://www.cnblogs.com/kevingrace/p/5651427.html 下面重点记录下jenk ...

  3. 【转】【WPF】 WPF 调用API修改窗体风格实现真正的无边框窗体

    WPF中设置无边框窗体似乎是要将WindowStyle设置为None,AllowTransparency=true,这样才能达到WinForm中无边框窗体的样式.但是AllowTransparency ...

  4. nginx缓存模块配置总结proxy_cache(未完)

    简介:此缓存设置用到了第三方模块purge,使用的时候就在源链接和访问的具体内容之间加入关键字"/purge/"即可. 如:访问http://192.168.0.1/a.png 会 ...

  5. REST风格的原则

    一个好的RESTful API,应该具备以下特征: 这个API应该是对浏览器友好的,能够很好地融入Web,而不是与Web格格不入. 浏览器是最常见和最通用的REST客户端.好的RESTful API应 ...

  6. 在64位windows下使用instsrv.exe和srvany.exe创建windows服务

    在64位windows下使用instsrv.exe和srvany.exe创建windows服务   在32位的windows下,包括windows7,windows xp以及windows 2003, ...

  7. C++创建对象的两种方式

    C++创建对象有两种方式,在栈上创建对象(Objects on the Stack)和在堆上创建对象(Objects on the Heap). 假设我们有以下的类: #include <str ...

  8. Android webview使用详解

    1. 打开网页时不调用系统浏览器, 而是在本WebView中显示: mWebView.setWebViewClient(new WebViewClient(){ @Override public bo ...

  9. Google java代码风格导入Eclipse

    Git地址 https://github.com/codeset/google-java-styleguide 下载配置文件在Eclipse中执行导入:Window -> Preferences ...

  10. [CareerCup] 5.1 Insert Bits 插入位

    5.1 You are given two 32-bit numbers, N and M, and two bit positions, land j. Write a method to inse ...