设为首页  
联系我们  
加入收藏  
网页制作 冲浪宝典 图形图像 操作系统 软件教学 编程开发 认证考试 安全技术 站长专区 文学驿站 娱乐天地 游戏天地 办公软件
文章搜索
您的位置: 首页 >> 文章首页 >> 编程开发 >> Java >> Convert from type X to type Y
精品推荐
Java点击TOP10
·我写的Java学生成绩管理系统源代码
·java笔试题
·异常java.sql.SQLException: Io exception:The Network Adapter could not establish connection
·MyEclipse 下开发JSF教程
·java网络五子棋的源代码
·servlet和JSP过滤器Filter
·用Eclipse Visual Editor 开发SWT GUI
·JSF+Spring+Hibernate的实例讲解(原创翻译)
·一个相对不错的地区代码级联实现
·《Thinking in Java》读书笔记
编程开发点击TOP10
·数字小键盘指法练习
·ASP.NET 程序中常用的三十三种代码
·用C语言编通讯录程序(初学者级别的)
·我写的Java学生成绩管理系统源代码
·CHK文件恢复工具
·Modem 常用AT指令集
·java笔试题
·异常java.sql.SQLException: Io exception:The Network Adapter could not establish connection
·单片机模拟I2C总线及24C02(I2C EEPROM)读写实例(源代码)
·C++经典电子书下载
精选专题

Convert from type X to type Y

作者: 来源:网络文章 时间:2005-12-16 22:41:50

integer to String :

 int i = 42; String str = Integer.toString(i);

or
 String str = "" + i

double to String :

 String str = Double.toString(i);

long to String :

 String str = Long.toString(l);

float to String :

 String str = Float.toString(f);

String to integer :

 str = "25"; int i = Integer.valueOf(str).intValue();

or
 int i = Integer.parseInt(str);

String to double :

 double d = Double.valueOf(str).doubleValue();

String to long :

 long l = Long.valueOf(str).longValue();

or
 long l = Long.parseLong(str);

String to float :

 float f = Float.valueOf(str).floatValue();


decimal to binary :

 int i = 42; String binstr = Integer.toBinaryString(i);


decimal to hexadecimal :

 int i = 42; String hexstr = Integer.toString(i, 16);

or
 String hexstr = Integer.toHexString(i);


hexadecimal (String) to integer :

 int i = Integer.valueOf("B8DA3", 16).intValue();

or
 int i = Integer.parseInt("B8DA3", 16);

ASCII code to String :

 int i = 64; String aChar = new Character((char)i).toString();


integer to ASCII code (byte) :

 char c = 'A'; int i = (int) c; // i will have the value 65 decimal


To extract Ascii codes from a String :

String test = "ABCD";for ( int i = 0; i < test.length(); ++i ) {char c = test.charAt( i );int i = (int) c;System.out.println(i);}


integer to boolean :

 b = (i != 0);

boolean to integer :

 i = (b)?1:0;

note :To catch illegal number conversion, try using the try/catch mechanism.

 try{i = Integer.parseInt(aString);} catch(NumberFormatException e){}
v


Convert from type X to type Y 相关文章:
Convert from type X to type Y 相关软件:
特别声明:本站除部分特别声明禁止转载的专稿外的其他文章可以自由转载,但请务必注明出处和原始作者。文章版权归文章原始作者所有。对于被本站转载文章的个人和网站,我们表示深深的谢意。如果本站转载的文章有版权问题请联系编辑人员,我们尽快予以更正。
转载请注明来源:http://www.xgdown.com