神马情况下 该重写方法
来源:互联网 发布:centos sftp 编辑:程序博客网 时间:2024/05/16 10:42
/*
*神马情况下 该重写方法
*/
import java.util.*;
class Name
{
private String firstname,lastname;
Name(String firstname,String lastname)
{
this.firstname = firstname;
this.lastname = lastname;
}
public String getfirstname()
{
return firstname;
}
public String getlastname()
{
return lastname;
}
public String toString()//重写tostring方法
{
return firstname+" "+lastname;
}
}
public class Testcon2
{
public static void main(String[] args)
{
Collection c = new HashSet();
Name n = new Name("f2","l2");
c.add("hello");
c.add(new Name("f1","l1"));
c.add(new Integer(100));
c.remove("hello");
c.remove(new Integer(100));//删除的执行过程为 会逐个比较set内的对象 有字符相同的的删除
//要用到equals方法,若此类对象没有重写equals方法则 需要重写equals方法)
System.out.println(c.remove(new Name("f1","l1")));//name 类型的对象没有重写equals方法 所以返回为false
System.out.println(c);
System.out.println(n);//只有重写了tostring方法 返回才是 name类型
}
}
*神马情况下 该重写方法
*/
import java.util.*;
class Name
{
private String firstname,lastname;
Name(String firstname,String lastname)
{
this.firstname = firstname;
this.lastname = lastname;
}
public String getfirstname()
{
return firstname;
}
public String getlastname()
{
return lastname;
}
public String toString()//重写tostring方法
{
return firstname+" "+lastname;
}
}
public class Testcon2
{
public static void main(String[] args)
{
Collection c = new HashSet();
Name n = new Name("f2","l2");
c.add("hello");
c.add(new Name("f1","l1"));
c.add(new Integer(100));
c.remove("hello");
c.remove(new Integer(100));//删除的执行过程为 会逐个比较set内的对象 有字符相同的的删除
//要用到equals方法,若此类对象没有重写equals方法则 需要重写equals方法)
System.out.println(c.remove(new Name("f1","l1")));//name 类型的对象没有重写equals方法 所以返回为false
System.out.println(c);
System.out.println(n);//只有重写了tostring方法 返回才是 name类型
}
}
- 神马情况下 该重写方法
- iOS ARC MRC情况下重写setter getter方法
- iOS ARC MRC情况下重写setter getter方法
- iOS ARC MRC情况下重写setter getter方法
- equals()方法很多情况下需要重写
- iOS MRC情况下重写setter getter方法
- 神马是url重写?
- windows 8专业版下播放视频的神马情况?
- 这个是神马情况???
- 学习笔记-JAVA-考点10-什么情况下需要重写equals和hashcode()两个方法?
- 位图索引什么情况下该使用?
- 纷纷抛弃机顶盒业务,神马情况?
- 没有事务是个神马情况呢
- WIPE与Format的种种神马情况
- 28.ARC情况下dealloc重写的作用
- Java中,重写的情况下子类调用父类
- 重写setter与getter方法以及其使用情况
- [转载]什么情况下该使用变量延迟?
- Xcode运行不了API文档给的代码或是以前的工程
- C++第11周项目2(9)参考——污损的数字
- DirectUI之CtreeCtrl(一)
- 31个省区市选出1556名十八大代表(名单)
- Frustum culling
- 神马情况下 该重写方法
- all163e:unknown opcode
- std::map的一次错误应用(日积月累)
- 移动互联网的到来
- 深入体验JavaWeb开发内幕——pageContext对象与JSP中标签的简介和相关应用
- 自然数1-n,不使用循环和分支语句的相关问题
- 统计用户占用多大的空间,一行数据超过4k
- 见的网络服务器软件综合比较介绍(apache、IIS、tomcat、jboss、resin、weblogic、websphere)
- 工作组下,配置使用web方式修改文件服务器用户帐户密码