List<PhoneBook> list = new ArrayList<PhoneBook>();
String str = "new PhoneBook("David","234567");";
How can I add (or convert) str
to code and add it to the list?
I have searched all over the internet, and didn't find anything helpful.
List<PhoneBook> list = new ArrayList<PhoneBook>();
String str = "new PhoneBook("David","234567");";
How can I add (or convert) str
to code and add it to the list?
I have searched all over the internet, and didn't find anything helpful.
To convert it to fit the arraylist you've given:
List<PhoneBook> list = new ArrayList<>();
PhoneBook not_a_str = new PhoneBook("David","234567");
list.add(not_a_str);
To add strings to a list of objects:
List<Object> list = new ArrayList<>();
String str = "new PhoneBook(\"David\",\"234567\")";
list.add(str);
To add strings to a list of strings (also objects):
List<String> list = new ArrayList<>();
String str = "new PhoneBook(\"David\",\"234567\")";
list.add(str);
list.add("Anything else");
Good luck with java