转换java

来源:互联网 发布:java多态的实现原理 编辑:程序博客网 时间:2024/06/06 17:14
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 转成字串的方法大同小异.
 
int -> String 


int i=12345;
String s="";
第一种方法:s=i+"";
第二种方法:s=String.valueOf(i);
这两种方法有什么区别呢?作用是不是一样的呢?是不是在任何下都能互换呢?


String -> int 


s="12345";
int i;
第一种方法:i=Integer.parseInt(s);
第二种方法:i=Integer.valueOf(s).intValue();
这两种方法有什么区别呢?作用是不是一样的呢?是不是在任何下都能互换呢?


以下是答案:


第一种方法:s=i+""; //会产生两个String对象
第二种方法:s=String.valueOf(i); //直接使用String类的静态方法,只产生一个对象


第一种方法:i=Integer.parseInt(s);//直接使用静态方法,不会产生多余的对象,但会抛出异常
第二种方法:i=Integer.valueOf(s).intValue();//Integer.valueOf(s) 相当于 new Integer(Integer.parseInt(s)),也会抛


异常,但会多产生一个对象


--------------------------------------------------------------------
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数据类型转换


关键字   类型转换


这是一个例子,说的是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中找到,整理一下做个备份。
define(function(require) {
var $ = require("jquery");
var Model = function() {
this.callParent();
};
Model.prototype.submitClick = function(event) {
var commentData = this.comp("commentData");
if (commentData.isValid()) {
var author = commentData.val("author");
var comment = commentData.val("comment");
if (author && comment) {
var data = this.comp("data");
data.add({
author : author,
comment : comment
});


commentData.setValue("author", "");
commentData.setValue("comment", "");
}
} else {
justep.Util.hint(commentData.getInvalidInfo());


}


};


return Model;
});
list嵌套需要注意的问题


原因:很多用户在做list嵌套的时候,由于一些细节配置的原因不明白,导致运行不成功!下面我说下list嵌套中需要注意的点
解决方案:
1.第二层的list组件需要设置filter属性,表示根据第一次list当前行数据过滤出符合条件要显示的数据,比如: $row.val(‘id’)==$object.val(‘ID’),其中
$row.val(‘id’)表示的是第二个list绑定的data的字段
$object.val(‘ID’)表示的是第一个list组件(父)绑定的data字段!
意思就是根据第一个list组件中当前行的ID过滤出第二个list组件中 id=ID 的数据
(理解一下含义!
$row 是list 上层的当前行!
$object是 list 里层对应当前行
分界线就是class属性 x-list-template 上层dom节点用$row ,下层的就是$object
所以 第二个list 的 filter属性 $row 表示里层list的当前行,,$object表示外层list的当前行!
里层list中获取父层的当前行对象可以使用$parent



2.第二层list对应的data组件数据应该一次性加载到data组件中(为了全部显示,保证第一层的子数据全部存在,或者设置过滤条件!根据第一层已经加载的数据的ID去查下第二层数据),所以 data组件autoLoad 设置为true,limit设置为-1,第二层list的limit属性设置为-1


3.如果有scrollView组件配合使用,第二层的list组件的 disableInfiniteLoad 和 disablePullToRefresh 都设置为true,这个属性表示禁止上下拉触发刷新数据,只对外层list组件起作用就行了!


4.list嵌套一般两层就够了!如果有三层list嵌套,页面加载会特别慢的,因为3层嵌套循环,非常耗时的,两层list嵌套,在数据量特别大的情况下,也是非常耗时的!所以数据量比较大的时候,不建议使用list嵌套实现!应该是通过主从表的格式现实页面!效率会快很多的 http://docs.wex5.com/wex5-ui-question-list-2072
原创粉丝点击