Following is the workflow:
Class A{
B obj_b = new B;
String x= "abc";
String y= "def";
public void method_a(){
obj_b.method_b(x,y);
}
}
Class B{
C obj_c = new C;
public String method_b(String Fname, String Lname){
ArrayList<String> names = new ArrayList<String>();
names.add(Fname);
names.add(Lname);
String qwerty=("Hello"+ obj_c.method_c(names));
}
}
Class C{
public String method_c(ArrayList<String> allElements){
String xyz = MessageFormat.format(allElements.get(0),allElements.get(1));
return xyz;
}
}
What I want to do is:
- In Class B, to add all the arguments directly to the ArrayList(i.e. Fname and Lname to names array list). Number of arguments may vary.There might be some other method calling method_b() with 3 or 4 arguments, that is why I am using ArrayList.
- Then in Class C, putting each element of the array list(i.e. names) in the method,message(),with comma separated.
Please suggest if any better approach can be taken.
al.add(Fname);-- what isal? Please post code that can be compiled, this is not valid Java code asalis not declared anywhere.method_cis ignoring all but the first 2 elements in theArrayList.