java中的toString() 方法(多看本文的例子!)
toString() 方法:
toString()方法在Object类中定义,其返回值是String类型,描述当前对象的有关信息
在进行String与其它类型数据的连接操作时,自动调用toString()方法
可以根据需要在用户自定义类型中重写toString()方法
基本类型数据转换为String类型时,调用了对应封装类的toString()方法
public class Person {
private String name;
private int age;
private char sex;
public Person()
{
}
public Person(String name,int age, char sex)
{
this.name = name;
this.age = age;
this.sex = sex;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public char getSex() {
return sex;
}
public void setSex(char sex) {
this.sex = sex;
}
public boolean equals(Object obj)
{
if(obj==null)
{
return false;
}
if(obj==this)//传递进来的参数是否等于本对象
{
相关文档:
platform ['plætfɔ:m] n.平台
standard edition标准版
enterprise ['entəpraiz] n. 企业
bytecode n.字节码,字节代码
verifier n. 检验机
modifier [‘mɔdifaiə] n.修饰语
attribute [‘ætribju:t] vt.(to)把…归因于n.属性,特性
declaration ......
自 java 平台从 1995 年作为一个整体引入编程社区开始,它的发展已经远远超出了早期 java 专家和推介者所设想的“applet 无处不在”这一远景。相反,java 世界出现了 Swing、与 servlet 结合,从而发展为 J2EE、出现了 EJB、超越了 Spring 和 Hibernate、添加了泛型,变得越来越具有动态性,然后实现了函数化,在 ......
FacesContext context = FacesContext.getCurrentInstance();
HttpServletRequest request = (HttpServletRequest) context.getExternalContext().getRequest();
String parameterValue = request.g ......
一、JAVA获取随机数的方法
//使用java.lang.Math类的random()方法
double a = Math.random();
System.out.println("0.0-1.0的随机数:" + a);
double b = Math.random()*100;
System.out.println("0.0-100.0的随机数:" + b);
int c = (int)(Math.random()*100);
System.out.println("0-100的随机整数:" + c); ......
==操作符与equals方法的区别:
==是引用类型比较引用(也就是比较内容和地址);基本类型比较值;
equals()方法只能比较引用类型,"=="可以比较引用类型及基本类型;
特例:当用equals()方法进行比较时,对类File、String、Date及封装类(Wrapper包装 ......