Passing A String From One Method To Another Method
I need to pass a String from one method to another method and now I'm a bit clueless. The String values (callbackURL & donationId) I want to pass are inside this method: public
Solution 1:
publicvoidpostData(){
.
.
.
.
String callbackURL = tokens.nextToken();
String donationId = tokens.nextToken();
examplePayment(callbackURL, donationId);
}
privatevoidexamplePayment(String callback, String donationid){
//deal with your callback and donationid variables
}
Solution 2:
You pass values to another method by declaring the parameters in the method signature, for example:
privatevoidexamplePayment(String callbackURL, String donationId) {
//your logic in here
}
Then you can call it in your code like so:
publicvoidpostData() {
String callbackURL = tokens.nextToken();
String donationId = tokens.nextToken();
examplePayment(callbackURL, donationId);
}
Solution 3:
You mean you want to pass the strings to the function as arguments?
publicvoidpostData() {
.
.
.
String callbackURL = tokens.nextToken();
String donationId = tokens.nextToken();
examplePayment(callbackURL, donationId);
}
.
.
.
privatevoidexamplePayment(String callbackURL, String donationId) {
.
.
.
}
Solution 4:
publicvoidpostData() {
String callbackURL = tokens.nextToken();
String donationId = tokens.nextToken();
examplePayment(callbackURL,donationId);
}
privatevoidexamplePayment(String callbackURL,String donationId){
}
Solution 5:
publicStringpostData() {
String callbackURL = tokens.nextToken();
String someID = tokens.nextToken();
this.examplePayment(callbackURL, someID);
}
ORprivateexamplePayment(String callbackURL, String someID){
// DO whatever you want with callback and someID
}
Post a Comment for "Passing A String From One Method To Another Method"