I have a string named "var" where the text string is set as doc1, doc2 or doc3
String var = "doc2" // doc1 or doc2 or doc3
I get content from the website using Jsoup this way
Document doc_comp = Jsoup.connect("http://www.computer.org").get();
Elements doc1_comp = doc_comp.select("ul > doc1" );
Elements doc2_comp = doc_comp.select("ul > doc2" );
Elements doc3_comp = doc_comp.select("ul > doc3" );
I use switch case for the corresponding values to be printed
switch(var)
{
case "doc1": System.out.println(doc1_comp.text());
break;
case "doc2":System.out.println(doc2_comp.text());
break;
case "doc3":System.out.println(doc3_comp.text());
break;
default: System.out.println("no info");
}
Everything works perfectly fine with the switch case but I want to use a single line of code to replace switch case like this
System.out.println(var.concat("_comp.text()"));
but it straight away prints as a string "var_comp.text()" but does not execute it and print the content inside it.
Is there a way around to make it run