There is such a code:
... public static final String APP_STORAGE = "AppStorageFile"; public static final String Name_1 = "TextName7"; private SharedPreferences SFE; @Override protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); SFE = getSharedPreferences(APP_STORAGE, Context.MODE_PRIVATE); ... SharedPreferences.Editor editor = SFE.edit(); editor.putString(Name_1, "Привет мир")); editor.apply(); i = 1; String Name_number = "Name_" + String.valueOf(i); Log.d("TAG_LOG", Name_number); if (SFE.contains(Name_number)) { Log.d("TAG_LOG", "Зашло"); } else{ Log.d("TAG_LOG", "Не зашло"); } } As a result, it is written in the logs:
Name_1Не зашлоName_1
How to write correctly so that I Зашло in the logs and at the same time be able to change the value in brackets.
For each
Name_i, where i = 1.2 ... 100 there is the same code. And in order not to paint it 100 times, I decided to useString Name_number = "Name_" + String.valueOf(i);