您的位置:首页 > 编程语言 > Java开发

关于java的一些小问题,list中添加对象,java基本数据类型对象

2016-06-10 01:57 1016 查看
List<QuestionAnswer> questionAnswers = new ArrayList<QuestionAnswer>();
List<Question> questions = survey.getQuestions();
Iterator<Question> it = questions.iterator();
Question question = new Question();
while(it.hasNext()){
question = it.next();
QuestionAnswer questionAnswer = new QuestionAnswer();

//必须每次new一个新的对象,否则add后一次添加会覆盖前一次。因为对于List<T>来说,如果T是引用类型,那保存的是引用,如果是值类型,保存的是值本身!

    BeanUtils.copyProperties(question, questionAnswer);
    questionAnswers.add(questionAnswer);
}

class  Test

{
public static void main(String[] args) 
{

Long a = 0L;
System.out.println("a == 0L ? " + (a==0L));
System.out.println("a == 0 ? " + (a==0));
Long b = 0L;
System.out.println("a == b ? " + (a==b));
System.out.println("a equals b ? " + (a.equals(b)));

Long c = new Long(0);

        Long d = new Long(0);
System.out.println("c == d ? " + (a==b));
System.out.println("c equals d ? " + (a.equals(b)));

Long e = new Long(3);

        Long f = new Long(3);

        System.out.println("e == f ? " + (e==f));

}

}

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: