简体   繁体   中英

Passing the String value from one function to another without passing that string as a parameter

I don't is this possible but what I am trying to do is passing the String from the one function to another function without passing that as a parameter.

In this code, the String result is already being pass through doInBackground, and I tried to do through calling the function but as there is a need of passing arguments, but I am not trying to figure out the one passing the value.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_convert);
    String first = "Hero";
    nameFor(first);
}

private String nameFor(String s){
    Log.i("name", s);
    return s;
}

private void loadInto(String result) throws JSONException {
    String check = nameFor(*****);
}

Through this code, I am trying to get is that String first in the loadInto function storing that value check. The String result already have a JSON object. Any help will be really appreciated, really stuck.

Strings are immutable so both of these will work fine.

  String a = "Hello Wrold!";
  String copy_of_a = new String(a);
  String a = "Hello World!";
  String copy_of_a = a;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM