0

this is my method it has two argument with arrayList

private static PriorityInfo getPrioritiesInfo(ArrayList priorityNumber ,ArrayList priorityDate) {
        PriorityInfo priorityInfo = new PriorityInfo();
        ArrayList temp = new ArrayList();
        for(int i=0;i<priorityNumber.size();i++){          
            priorityInfo.setPriorityNo(toString(priorityNumber.get(i)));            
        }       

        //priorityInfo.setPriorityDate(priorityDate);
        return priorityInfo;
    }

My expected:

in the priorityNumber arraylist have n number of item (i.e 786975,293AS45), and i want to pass the each item into setPriorityNo method

the above method produce an error

method toString in class Object cannot be applied to given types;
  required: no arguments
  found: Object
  reason: actual and formal argument lists differ in length

setPriorityNo method its from PriorityInfo.class:

 public void setPriorityNo(String priorityNo) {
        this.priorityNo = priorityNo;
    }

let me know my mistake

3
  • Edit due to weak English needed. Commented Jul 21, 2016 at 7:20
  • @xenteros +1.... please go ahead! Commented Jul 21, 2016 at 7:21
  • What do you mean by +1? Anyway, I won't pick up correcting this one. Commented Jul 21, 2016 at 7:25

2 Answers 2

2

You are not converting to string correctly. you are referring to the toString method in the Object class.

try something like this:

private static PriorityInfo getPrioritiesInfo(ArrayList priorityNumber, ArrayList priorityDate) {
    PriorityInfo priorityInfo = new PriorityInfo(new ArrayList());
    ArrayList temp = new ArrayList();
    for(int i=0;i<priorityNumber.size();i++){
        priorityInfo.setPriorityNumbers(priorityNumber.get(i).toString());
    }

    //priorityInfo.setPriorityDate(priorityDate);
    return priorityInfo;
}

call the .toString() method on the ArrayList priorityNumber you are passing.

and your PriorityInfo class:

class PriorityInfo {

    private ArrayList priorityNumbers;

    public PriorityInfo(ArrayList priorityNumbers) {
        this.priorityNumbers = priorityNumbers;
    }

    public void setPriorityNumbers(String priorityNo) {
        this.priorityNumbers.add(priorityNo);
    }

    public ArrayList getPriorityNumbers() {
        return this.priorityNumbers;
    }

}

dont know which other methods you have in your PriorityInfo class.

Sign up to request clarification or add additional context in comments.

3 Comments

thanks but PriorityInfo class return only the last item in the arraylist
Yes i see the PriorityInfo has a bad design ill edit my post and come with am example what you could do
Thanks Aku,i have posted my answer also
0

i'm using Apache Commons library with StringUtils

 private static PriorityInfo getPrioritiesInfo(ArrayList priorityNumber ,ArrayList priorityDate) {
        PriorityInfo priorityInfo = new PriorityInfo();
        String temp="";

        for (int i = 0; i < priorityNumber.size(); i++) {
            String value = StringUtils.join(priorityNumber.get(i), '|');
            temp = temp.concat(value);
        }
 priorityInfo.setPriorityNo(temp);       
        return priorityInfo;
    }

1 Comment

you do not need the StringUtils. you can just do as so: temp = temp.concat(priorityNumber.get(i) + "|");

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.