简体   繁体   English

java:ArrayList()方法返回结果:如果传递参数或不传递参数

[英]java: ArrayList() method returning a result : if passing argument or without passing it

I want to write the method listCopies() that returns in an ArrayList all copies of a written work in a given language(eg : english); 我想编写一个方法listCopies(),该方法在ArrayList中返回给定语言(例如:英语)中所有书面作品的副本; if no language is given (empty string), all copies of the library will be returned (in all languages) . 如果未给出任何语言(空字符串),则将返回该库的所有副本(所有语言)。 This is the code i have developed but it doesnt work cause in the main(String[] args) {...} it calls 2 times this method , one with the argument passed and in the second without an argument : 这是我开发的代码,但是在main(String [] args){...}中不起作用,它调用此方法两次,一次调用传递参数,第二次调用不传递参数:

public ArrayList<Exemplary> listCopies(String l){
    ArrayList <Exemplary> tmp = new ArrayList<Exemplary>();
    for( int i = 0 ; i < copies.size(); i++){  
                 if(copies.get(i).getWrittenWork().getLanguage().equals(language)){ 
                tmp.add(Ex);
             }
    }
    return (tmp);}

I want to rewrite this code in a way that with or without argument (String lang) > it returns the array tmp . 我想以带或不带参数(String lang)>的方式重写此代码,它返回数组tmp。

There's a multitude of problems with your code: 您的代码有很多问题:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM