java - How to save a value of a String variable and use it later when i wish even every time i run the code? -


i have requirement have string values , have save values somewhere in list.and values once inserted list should remain there.so if want use values later should not put values in list again.i giving simple piece of code illustrate problem...

public class chkrecords {  public static void main(string a[]){      list<string> inti=new arraylist<>();        string arr[]={"a","b","c","d"};  //      for(int i=0;i<arr.length;i++){ //           //          inti.add(string.valueof(arr[i])); //      }      system.out.println(inti);  } } 

this piece of code trying implement ... loop going insert values first time.and don't want use loop again,but want values in list..can me....

how save value of string variable , use later when wish??

you can create variable instance variable like:

public class chkrecords {      private string var = "something";      public static void main(string a[]){         // can access var directly method in class.         system.out.println(var);     }      public string getvar() {// able access var variable outside class         return var;     } } 

and if want use var each time run program, can serialize object.


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -