Results 1 to 1 of 1
  1. #1
    bana1 is offline Member
    Join Date
    Jan 2014
    Posts
    1
    Rep Power
    0

    Question How to use a "contains(object)" method in ArrayList?

    First of all, I am not a native English speaker, so.... understand my poor writing plz :)
    I am making a Grade Calculator myself.
    I just found on the Internet that "contains" method easily works when you using ArrayList<String> or ArrayList<Integer>.
    But I have to use my own class... for instance.. ArrayList<Grade> - this class receives 3 valuables in constructor -
    "contains" doesn't work in my own class... I already tested.
    If I want to find duplication, do I have to use Iterator?

    I will show you parts of Grade and DAO class

    Java Code:
    public Grade(String subjectName, String category, double score) {
    		this.subjectName = subjectName;
    		this.score = score;
    		this.category = category;
    	}
    
    public int addGrade(Grade tempGrade) {
    		/*
    		Iterator<Grade> it = gradeList.iterator();
    		while(it.hasNext()){
    			Grade temp = it.next();
    		}
    		*/
    
    		if (gradeList.contains(tempGrade)) {
    			return DUPLICATION;
    		}
    		gradeList.add(tempGrade);
    		return SUCCESS;
    	}
    Last edited by bana1; 01-02-2014 at 11:12 PM.

Similar Threads

  1. Replies: 0
    Last Post: 12-07-2012, 08:29 AM
  2. Replies: 3
    Last Post: 10-30-2012, 03:06 PM
  3. Replies: 4
    Last Post: 06-14-2011, 04:59 AM
  4. Replies: 1
    Last Post: 10-20-2008, 07:35 AM
  5. Replies: 1
    Last Post: 07-16-2007, 06:32 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •