I have two classes namely Test and Demo and in Demo class I have a class variable namely List. I somehow need to put/add the given two strings into List but it will only accept objects of Test class. Is there a way I can add the given strings to List.
class Test{
List<Test> getdataFromDemo(){
return Demo.getData;
}
}
class Demo{
public static List<Test> getData=new LinkedList<Test>;
static void D1(){
String str1="TestOne";
String str2="TestTwo";
}
getData.add(str1);//need to add str to getData but this is showing error
getData.add(str2);
System.out.println(getData)
List<Test>means, you can only put Test objects in that list. Why do you want to put strings in there?List<String>