Reputation: 617
Is there any way to print the contents of void methods just like this in java
public boolean printings(String branchName){
if (findBranch(branchName)!=null){
myBranch.get(findTheBranch(branchName)).printCostumers();
return true;
}else{
System.out.println("Branch does not exist");
return false;
}
}
Note that methods findTheBranch is working properly and the printCostumers is also a void method
private int findTheBranch(String name){
for (int i=0;i<myBranch.size();i++){
if (myBranch.get(i).getName().indexOf(name)>=0){
return i;
}
}
return -1;
}
public void printCostumers(){
for(int i=0;i<myCostumer.size();i++){
System.out.println(myCostumer.get(i).getName()+":" );
for (int j=0; j<findTheCostumer(i).getTransaction().size();j++){
System.out.println(findTheCostumer(i).getTransaction().get(j));
}
}
}
Other methods that are not mendtioned are working properly. I've tried them in other examples.
Upvotes: 0
Views: 5903
Reputation: 331
Anywhere you include
System.out.println(String x);
Java will print out x. It doesn't matter whether or not it's in a void method.
void
in Java just refers to the return
statement (meaning a void method doesn't return anything). It doesn't mean that the method can't output something (on the console, window, printer or somewhere else)
Also concerning your actual code: Your loop most likely doesn't print anything as it most likely is handed an empty list.
Upvotes: 2