Unfortunately my Java knowledge is somewhat lacking so this is somewhat of a beginner's question but I can't seem to figure out how I can do this.
Essentially I have a method that creates and populates an ArrayList. The said populated list is something that I want to use in a different method and potentially another class. I think that it is a class level variable I want to save it as but I'm not sure how to do this. The code below will make it more clear.
public class JenAcc {
private final String endpointUrl = "http://a-url/";
private String uri = "api/json";
public static void main(String[] args) {
JenAcc obj = new JenAcc();
obj.jsonRun();
}
public void jsonRun() {
ArrayList<String> abbrevList = new ArrayList<>();
ArrayList<String> urlList = new ArrayList<>();
try {
RestServiceClient client = RestServiceClient.getClient(endpointUrl);
Response response = client
.path(uri)
.accept(MediaType.APPLICATION_JSON)
.get();
String s = (String) response.getEntity();
JobList jjj = JSONResponseHandler.mapJSONToResponse(s, JobList.class);
for (int i = 0; i < jjj.getJobs().size(); i++) {
if (jjj.getJobs().get(i).getName().contains("services"){
abbrevList.add(jjj.getJobs().get(i).getName().replace("services", ""));
urlList.add(jjj.getJobs().get(i).getUrl());
} else i++;
}
System.out.println(abbrevList);
System.out.println(urlList);
} catch (Exception e) {
e.printStackTrace();
}
}
}
So essentially I want to have a way to make use of that list outside of that method, in another method or class. How would I go about doing that?
Thanks for your patience.