I want to convert the ArrayList of (TestObject) to a String and vice versa. I have attached the main activity as well so you can see the methods I want to create.
MainActivity: Where ArrayList is made and needs to be converted to a String.
public class MainActivity extends AppCompatActivity {
ArrayList<TestObject> testObjects;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
testObjects = new ArrayList<>();
testObjects.add(new TestObject("Name1", "Attribute1"));
testObjects.add(new TestObject("Example", "Example"));
}
private String convertObjectArrayToString(ArrayList<TestObject> arrayToBeConverted){
return null;
}
private ArrayList<TestObject> convertStringToObjectArray(){
return null;
}
}
Object in ArrayList:
public class TestObject {
private String name;
private String attribute;
TestObject(String name, String attribute){
this.name = name;
this.attribute = attribute;
}
public void setAttribute(String attribute) {
this.attribute = attribute;
}
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
public String getAttribute() {
return attribute;
}
}
TestObjectclass