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 i = 64;
String aChar = new Character((char)i).toString();
integer to ASCII code c = 'A';
int i = (int) c; // i will have the value 65 decimal
To extract Ascii codes from a 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 =
note :
To catch illegal number conversion, try using the try/catch mechanism.
try{
i = Integer.parseInt(aString);
}
catch(NumberFormatException e)
{
}

java中String类型转换方法的更多相关文章

  1. Java中String类型细节

    Java中String类型细节 一 . String两种初始化方式 1 . String str1= “abc”;//String类特有的创建字符对象的方式,更高效 在字符串缓冲区中检测”abc”是否 ...

  2. Java中String类型详解

    这篇博客是我一直想总结的,这两天一直比较忙,先上传下照片吧,过后有时间再弄成正常的. 本文主要是对Java中String类型的总结,包括其在JVM中是怎么存储的...

  3. 【转载】 Java中String类型的两种创建方式

    本文转载自 https://www.cnblogs.com/fguozhu/articles/2661055.html Java中String是一个特殊的包装类数据有两种创建形式: String s ...

  4. 关于JAVA中String类型的最大长度

    前些天看到一道面试题,题目很容易理解:String的长度限制是多少? 针对这个题目,浏览了网友的回答,大概得到了3个层次的答案. 最浅的层次: 近似计算机内存大小的长度.这是作为一个程序员最浅显的回答 ...

  5. Java中String类型的数据比较

    在Java中如果想比较两个字符串是否相等,可以使用string1==string2 或string1.equal(string2)来比较. 但是,第一种方法过于局限.例如, String string ...

  6. Java中String类型的不可变性和驻留池

    一 基本概念 可变类和不可变类(Mutable and Immutable Objects)的初步定义: 可变类:当获得这个类的一个实例引用时,可以改变这个实例的内容. 不可变类:不可变类的实例一但创 ...

  7. java中String类型的相关知识

    String类方法整理说明: ·Length()用来求字符串的长度,返回值为字符串的长度: ·charAt()取该字符串某个位置的字符,从0开始,为char类型: ·getChars()将这个字符串中 ...

  8. java中String类型

    string对象常用方法 string对象比较方法: string类获取包含子串的方法: 字符串和数字的转换: String类 String对象是不可改变的,字符串一旦创建,内容不能再改变. 构造字符 ...

  9. Java中String类型的部分用法

    1.如何将字符串转换为整型数值? int i = Integer.parseInt("20"); 2.如何用“==”还是equals比较两个字符串? “==”是用来比较俩引用是不是 ...

随机推荐

  1. hdu 1576 求逆元

    题意:给出n=A mod 9973和B,求(A/B) mod 9973 昨天用扩展欧几里得做过这题,其实用逆元也可以做. 逆元的定义:例如a*b≡1 (mod m),则b就是a关于m的逆元. 求逆元方 ...

  2. repo 无法连接gerrit.googlesource.com 下载工具

    万恶的墙下,我们可以用其他的url来下载代码. 屏蔽掉repo里面的 #REPO_URL = 'https://gerrit.googlesource.com/git-repo' 在你的下载连接后添加 ...

  3. Linux下J2EE环境搭建

    1.下载MyEclipse 2010的linux安装包. myeclipse-10.1-offline-installer-linux 2.将下载MyEclipse 2010的linux安装包,使用X ...

  4. easyui form submit 不提交

    http://bbs.csdn.net/topics/390811964 function saveProduct() {             //$('#fm').form('submit',  ...

  5. 项目总结—jQuery EasyUI-DataGrid动态加载表头

    http://blog.csdn.net/zwk626542417/article/details/19248747 概要 在前面两篇文章中,我们已经介绍了在jQuery EasyUI-DataGri ...

  6. 栈的的顺序实例SeqStack实现

    1.#include <stdio.h>#include <stdlib.h>#include "SeqStack.h"/* run this progra ...

  7. WEB开发中的页面跳转方法总结

    PHP header()函数跳转 PHP的header()函数非常强大,其中在页面url跳转方面也调用简单,使用header()直接跳转到指定url页面,这时页面跳转是302重定向: $url = & ...

  8. PHP中PDO的配置与说明

    住[PDO是啥] PDO是PHP5新加入的一个重大功能,因为在PHP5以前的php4/php3都是一堆的数据库扩展来跟各个数据库的连接和处理,什么php_mysql.dll.php_pgsql.dll ...

  9. Sphinx学习之sphinx的安装篇

    一.  Sphinx简介 Sphinx是由俄罗斯人Andrew Aksyonoff开发的一个全文检索引擎.意图为其他应用提供高速.低空间占用.高结果 相关度的全文搜索功能.Sphinx可以非常容易的与 ...

  10. yii框架常用url地址

    调用YII框架中 jquery:Yii::app()->clientScript->registerCoreScript('jquery');        framework/web/j ...