Nickool Nickool - 1 year ago 64
Java Question

how to access List Object Methods?

I have a Seed key as below:
enter image description here
I know that if I want to access the class methods, they should be static:

here is my Cardkeyword class:

public class CardKeyword implements Comparable<CardKeyword> {

public CardKeyword(String stem) {
this.stem = stem;
public String getStem() {
return this.stem;
//some methods

here is my main class:

public static void main(String[] args) throws Exception {
String Seedurl = "";
List Seedkey=getXKeywords(Seedurl, 1);

public static List getXKeywords(String Url, int X) throws Exception {
String html = get(Url);
String plaintext = Jsoup.parse(html).text();
List<CardKeyword> wordlist = KeywordsExtractor.getKeywordsList(plaintext);
List lst = wordlist.subList(0, X);
return lst;

I want to get the stem from the Seedkey but I was not able to do it. How can I do it? If I change the
method to
public static getStem()
, it gives me error.

Answer Source

getXKeywords returns a list, you have to iterate its CardKeyword items to call getStem method. By the way in your current code the list is not parametrized. Replace List Seedkey with List<CardKeyword> Seedkey to deal with CardKeyword objects and not Object objects.