任何有关ArrayList问题的帮助 [英] Any help with an ArrayList problem

查看:86
本文介绍了任何有关ArrayList问题的帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对java很新,并且有一个Arraylist问题我想在竞争类中添加一些字符串,并从另一个中获取它们的toString,例如。



Hi I'm fairly new to java and have an Arraylist problem I want to add some Strings in a competition Class and get the toString of them from another such as for example.

import java.util.ArrayList;

public class Competition {

    private ArrayList<String> comp;

    public Competition(ArrayList<String> competition) {
        this.comp = competition;

    }

    public ArrayList<String> getComp() {
        return comp;
    }

    public void setComp(ArrayList<String> competition) {
        this.comp = competition;
        comp.add("hhh");
        comp.add("bbb");
    }

    @Override
    public String toString() {
        return "Competition [comp=" + comp + "]";
    }

}









从另一个类中获取toString







And get the toString from a different Class

public void listComp(){

        ArrayList<Competition> comp = new ArrayList<Competition>();

        System.out.println(comp.toString());
    }

推荐答案

这篇关于任何有关ArrayList问题的帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆