- 浏览: 281841 次
- 性别:
- 来自: 厦门
文章分类
最新评论
-
chenxliang:
2016年10月26、27日,上海浦东,Postgres中国用 ...
用JDBC连接Postgres(Postgres学习笔记1) -
cuiran:
不错,讲的很详细。
web.xml 中的listener、 filter、servlet 加载顺序及其详解 -
i_am_birdman:
PostgreSQL的管理启动服务pg_ctl -D /pat ...
PostgreSql 数据库备份恢复 删除 建立 -
i_am_birdman:
songshuang 写道现在觉悟也不晚!加油!
加油呵呵
人生规划啊 -
songshuang:
现在觉悟也不晚!加油!
人生规划啊
String.valueOf()是把java的原始数据类型或运用多态产生的Object类型转为String类型,以下是sun的String类的各valueOf()方法的源码:
/**
* Returns the string representation of the <code>Object</code> argument.
*
* @param obj an <code>Object</code>.
* @return if the argument is <code>null</code>, then a string equal to
* <code>"null"</code>; otherwise, the value of
* <code>obj.toString()</code> is returned.
* @see java.lang.Object#toString()
*/
public static String valueOf(Object obj) {
return (obj == null) ? "null" : obj.toString();
}
/**
* Returns the string representation of the <code>char</code> array
* argument. The contents of the character array are copied; subsequent
* modification of the character array does not affect the newly
* created string.
*
* @param data a <code>char</code> array.
* @return a newly allocated string representing the same sequence of
* characters contained in the character array argument.
*/
public static String valueOf(char data[]) {
return new String(data);
}
/**
* Returns the string representation of a specific subarray of the
* <code>char</code> array argument.
* <p>
* The <code>offset</code> argument is the index of the first
* character of the subarray. The <code>count</code> argument
* specifies the length of the subarray. The contents of the subarray
* are copied; subsequent modification of the character array does not
* affect the newly created string.
*
* @param data the character array.
* @param offset the initial offset into the value of the
* <code>String</code>.
* @param count the length of the value of the <code>String</code>.
* @return a newly allocated string representing the sequence of
* characters contained in the subarray of the character array
* argument.
* @exception NullPointerException if <code>data</code> is
* <code>null</code>.
* @exception IndexOutOfBoundsException if <code>offset</code> is
* negative, or <code>count</code> is negative, or
* <code>offset+count</code> is larger than
* <code>data.length</code>.
*/
public static String valueOf(char data[], int offset, int count) {
return new String(data, offset, count);
}
/**
* Returns the string representation of the <code>boolean</code> argument.
*
* @param b a <code>boolean</code>.
* @return if the argument is <code>true</code>, a string equal to
* <code>"true"</code> is returned; otherwise, a string equal to
* <code>"false"</code> is returned.
*/
public static String valueOf(boolean b) {
return b ? "true" : "false";
}
/**
* Returns the string representation of the <code>char</code>
* argument.
*
* @param c a <code>char</code>.
* @return a newly allocated string of length <code>1</code> containing
* as its single character the argument <code>c</code>.
*/
public static String valueOf(char c) {
char data[] = {c};
return new String(0, 1, data);
}
/**
* Returns the string representation of the <code>int</code> argument.
* <p>
* The representation is exactly the one returned by the
* <code>Integer.toString</code> method of one argument.
*
* @param i an <code>int</code>.
* @return a newly allocated string containing a string representation of
* the <code>int</code> argument.
* @see java.lang.Integer#toString(int, int)
*/
public static String valueOf(int i) {
return Integer.toString(i, 10);
}
/**
* Returns the string representation of the <code>long</code> argument.
* <p>
* The representation is exactly the one returned by the
* <code>Long.toString</code> method of one argument.
*
* @param l a <code>long</code>.
* @return a newly allocated string containing a string representation of
* the <code>long</code> argument.
* @see java.lang.Long#toString(long)
*/
public static String valueOf(long l) {
return Long.toString(l, 10);
}
/**
* Returns the string representation of the <code>float</code> argument.
* <p>
* The representation is exactly the one returned by the
* <code>Float.toString</code> method of one argument.
*
* @param f a <code>float</code>.
* @return a newly allocated string containing a string representation of
* the <code>float</code> argument.
* @see java.lang.Float#toString(float)
*/
public static String valueOf(float f) {
return Float.toString(f);
}
/**
* Returns the string representation of the <code>double</code> argument.
* <p>
* The representation is exactly the one returned by the
* <code>Double.toString</code> method of one argument.
*
* @param d a <code>double</code>.
* @return a newly allocated string containing a string representation of
* the <code>double</code> argument.
* @see java.lang.Double#toString(double)
*/
public static String valueOf(double d) {
return Double.toString(d);
}
/**
* Returns the string representation of the <code>Object</code> argument.
*
* @param obj an <code>Object</code>.
* @return if the argument is <code>null</code>, then a string equal to
* <code>"null"</code>; otherwise, the value of
* <code>obj.toString()</code> is returned.
* @see java.lang.Object#toString()
*/
public static String valueOf(Object obj) {
return (obj == null) ? "null" : obj.toString();
}
/**
* Returns the string representation of the <code>char</code> array
* argument. The contents of the character array are copied; subsequent
* modification of the character array does not affect the newly
* created string.
*
* @param data a <code>char</code> array.
* @return a newly allocated string representing the same sequence of
* characters contained in the character array argument.
*/
public static String valueOf(char data[]) {
return new String(data);
}
/**
* Returns the string representation of a specific subarray of the
* <code>char</code> array argument.
* <p>
* The <code>offset</code> argument is the index of the first
* character of the subarray. The <code>count</code> argument
* specifies the length of the subarray. The contents of the subarray
* are copied; subsequent modification of the character array does not
* affect the newly created string.
*
* @param data the character array.
* @param offset the initial offset into the value of the
* <code>String</code>.
* @param count the length of the value of the <code>String</code>.
* @return a newly allocated string representing the sequence of
* characters contained in the subarray of the character array
* argument.
* @exception NullPointerException if <code>data</code> is
* <code>null</code>.
* @exception IndexOutOfBoundsException if <code>offset</code> is
* negative, or <code>count</code> is negative, or
* <code>offset+count</code> is larger than
* <code>data.length</code>.
*/
public static String valueOf(char data[], int offset, int count) {
return new String(data, offset, count);
}
/**
* Returns the string representation of the <code>boolean</code> argument.
*
* @param b a <code>boolean</code>.
* @return if the argument is <code>true</code>, a string equal to
* <code>"true"</code> is returned; otherwise, a string equal to
* <code>"false"</code> is returned.
*/
public static String valueOf(boolean b) {
return b ? "true" : "false";
}
/**
* Returns the string representation of the <code>char</code>
* argument.
*
* @param c a <code>char</code>.
* @return a newly allocated string of length <code>1</code> containing
* as its single character the argument <code>c</code>.
*/
public static String valueOf(char c) {
char data[] = {c};
return new String(0, 1, data);
}
/**
* Returns the string representation of the <code>int</code> argument.
* <p>
* The representation is exactly the one returned by the
* <code>Integer.toString</code> method of one argument.
*
* @param i an <code>int</code>.
* @return a newly allocated string containing a string representation of
* the <code>int</code> argument.
* @see java.lang.Integer#toString(int, int)
*/
public static String valueOf(int i) {
return Integer.toString(i, 10);
}
/**
* Returns the string representation of the <code>long</code> argument.
* <p>
* The representation is exactly the one returned by the
* <code>Long.toString</code> method of one argument.
*
* @param l a <code>long</code>.
* @return a newly allocated string containing a string representation of
* the <code>long</code> argument.
* @see java.lang.Long#toString(long)
*/
public static String valueOf(long l) {
return Long.toString(l, 10);
}
/**
* Returns the string representation of the <code>float</code> argument.
* <p>
* The representation is exactly the one returned by the
* <code>Float.toString</code> method of one argument.
*
* @param f a <code>float</code>.
* @return a newly allocated string containing a string representation of
* the <code>float</code> argument.
* @see java.lang.Float#toString(float)
*/
public static String valueOf(float f) {
return Float.toString(f);
}
/**
* Returns the string representation of the <code>double</code> argument.
* <p>
* The representation is exactly the one returned by the
* <code>Double.toString</code> method of one argument.
*
* @param d a <code>double</code>.
* @return a newly allocated string containing a string representation of
* the <code>double</code> argument.
* @see java.lang.Double#toString(double)
*/
public static String valueOf(double d) {
return Double.toString(d);
}
发表评论
-
Thinking in java 读书笔记
2012-03-13 09:32 0面向对象语言的5个特性: 1.万物皆为对象。 2.程序是对象的 ... -
java应用打包jar,jar转换exe
2012-02-13 10:16 966java projects 打包jar的方法: (1):用ec ... -
几种基本的数字正则表达式
2011-04-06 20:20 1260只能输入1个数字 表达式 ^\d$ 描述 ... -
坚持着
2010-12-26 22:35 799有时候不知道为什么,明明知道没有希望,没有意义,还是要坚持,为 ... -
JDK自带的native2ascii工具
2010-12-15 10:40 723背景:java默认的编码方式为Unicode,而计算机系统编码 ... -
对象的序列化和反序列化
2010-12-06 20:22 820当两个进程在进行远程 ... -
Java的序列化机制
2010-12-06 20:22 833Java的序列化机制只序列化对象的属性值,而不会去序列化什么所 ... -
浅谈异常处理
2010-12-06 12:46 634六种异常处理的陋习 你觉得自己是一个Java专家吗?是否肯定 ... -
java.io.Reader和java.io.Writer
2010-11-11 10:33 137114.3 字符流 java.io.Reader、java ... -
Java 反射机制深入研究
2010-11-06 17:50 827Java 反射是Java语言的一个很重要的特征,它使得Java ... -
Abstract Class and Interface 抽象类与接口的区别
2010-11-03 19:58 1138abstract Methods and Classes -- ... -
关于String,StringBuffer,StringBuilder,+和append
2010-09-14 15:17 890String一旦赋值或实例化后就不可更改,如果赋予新值将会重新 ... -
关于对象的equal方法和hashCode方法
2010-09-08 13:28 1341equal方法 Object类的equals方法用于检测一个对 ... -
Java 重写Object类的常见方法
2010-09-08 13:14 1424当我们写一个类的时候,都会对Java.lang.Obje ... -
arraylist的使用方法
2010-06-19 21:08 10171、什么是ArrayList ArrayList ... -
myeclipse基本设置
2010-06-15 15:26 12191.myeclipse如何显示行数 Window->P ... -
Java多线程编程要点 (二)
2010-06-14 13:20 7884、 Timer 和 Timer Task 的 ... -
Java多线程编程要点 (一)
2010-06-14 13:17 7621、 认识Thread和Runnable Java中实现多线程 ... -
一些基础
2010-06-11 19:39 7851 notify与notifyall的区别 notify和no ...
相关推荐
`String.valueOf()`方法在Java中是一个非常实用的工具,它用于将各种数据类型转换为String类型。这个方法在处理不同类型的数据时有不同的行为,下面我们详细探讨一下。 1. **空值和未定义**: `undefined`和`null`...
Java中Integer.valueOf、parsetInt() String.valueOf的区别和结果代码解析 Java中Integer.valueOf、parsetInt()和String.valueOf都是常用的方法,但是它们之间存在着很多的区别,下面我们将通过代码来解释它们之间...
通常,为了提高代码的可读性和执行效率,推荐使用`String.valueOf()`进行`int`到`String`的转换,以及使用`Integer.parseInt()`进行`String`到`int`的转换。这些方法不仅简单明了,而且性能优越。
Log.i("firstVisibleItem=",String.valueOf(firstVisibleItem)); Log.i("visibleItemCount=",String.valueOf(visibleItemCount)); Log.i("totalItemCount=", String.valueOf(totalItemCount)); //这里要减二,...
String strI = String.valueOf(i); ``` 对于对象,如果对象非null,`String.valueOf()`实际上就是调用了`toString()`方法。如果对象是null,`String.valueOf()`会返回"null"字符串。 3. **StringBuilder / ...
btn_start.setTag(String.valueOf(position)); btn_pause.setTag(String.valueOf(position)); btn_stop.setTag(String.valueOf(position)); btn_continue.setTag(String.valueOf(position)); pb_...
btn_start.setTag(String.valueOf(position)); btn_pause.setTag(String.valueOf(position)); btn_stop.setTag(String.valueOf(position)); btn_continue.setTag(String.valueOf(position)); pb_progressBar....
在 Java 中,可以使用 String.valueOf() 方法将 int 类型的变量转换为 String 类型的变量。例如: int intvar = 1; String stringvar; stringvar = String.valueOf(intvar); 4. float --> String 转换 在 Java 中...
例如,`String.valueOf(int i)`会将一个整数转换为它的字符串表示,而`String.valueOf(char c)`则会将字符转换为它的字符串形式。这种方法在需要将非字符串数据输出或拼接时非常有用。 除了这两个常见的使用场景,`...
String.valueOf(pageSize),String.valueOf((pageNumber-1)*pageSize)});) 2、ListView 分批加载(listView的setOnScrollListener事件的掌握和逻辑的判断操作) 3、ListView 的两种优化(View对象复用和JavaBean...
String t=String.valueOf(st.charAt(i)); r.concat(t); System.out.println(r); }*/ if(st.length()==1){ jt.setText("0"); j=0;a=0;n=0;g=0; } else{ if(".".equals(String....
public int compare_130(int a,int ... String msg = String.valueOf(a) + " compare with " + String.valueOf(b) + ",the " + String.valueOf(result)+" is bigger"; labelView.setText(msg); } });
在Java编程语言中,将对象转换为字符串是一个常见的操作,主要涉及到`toString()`、`(String)`类型转换以及`String.valueOf()`这三个方法。了解它们的区别和使用场景对于编写高质量的Java代码至关重要。 首先,`...
动态生成数的运用 ... String msg = String.valueOf(a) + " compare with " + String.valueOf(b) + ",the " + String.valueOf(result)+" is bigger"; labelView.setText(msg); } });
String s = String.valueOf(i); 2. 使用 Integer.toString() 方法 String s = Integer.toString(i); 3. 使用字符串连接符 String s = "" + i; 四、将 int 转换成 Integer 将 int 转换成 Integer 可以使用以下...
mTvDef.setText(getResources().getString(R.string.text_def)+" : "+String.valueOf(seekBar.getProgress())); break; } case R.id.seekbar_self: { // 设置“与自定义SeekBar对应的TextView”的...
}else if(s3.equals("-")){t1.setText(String.valueOf(v1-v2));}else if(s3.equals("*")){t1.setText(String.valueOf(v1*v2));}else if(s3.equals("/")){if(v2==0){JOptionPane.showMessageDialog(null,"除数不能为0...
b0.set(key,new StringBuffer(prefix1).append(".").append(String.valueOf(i)).append(".").append(String.valueOf(j)).toString()); } else{//如果下级是如果是文本或值,就放进书包 ...