Check out example codes for "Java arraylist if you don't want to use add()". It will help you in understanding the concepts better.

Code Example 1

public class MainActivity extends AppCompatActivity {

    protected void onCreate(Bundle savedInstanceState) {

        ListView myListView = (ListView) findViewById(;

        final ArrayList<String> myFriendsList = new ArrayList<String>(asList("Friend1", "Friend2", "Friend3", "Friend4", "Friend5"));

        // set the layout of the list
        ArrayAdapter<String> friendsArrayAdapter = new ArrayAdapter<String>(this,
                                                android.R.layout.simple_list_item_1, myFriendsList);

        // connect adapter to myFriendsList

        // set onClickListener
        myListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

                Toast.makeText(MainActivity.this, myFriendsList.get(position), Toast.LENGTH_SHORT).show();


Learn ReactJs, React Native from