我如何在BlueJ的一个ArrayList输入参数? [英] How do I enter parameters for an ArrayList in BlueJ?

查看:1288
本文介绍了我如何在BlueJ的一个ArrayList输入参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在BlueJ的,如果我写这需要一个数组作为参数,然后当我想测试方法用一个方法调用我必须输入用花括号中的元素,这样的方法:

In BlueJ, if I write a method that takes an array as a parameter, then when I want to test that method with a method call I have to enter the elements with curly braces, so:

{1,2,3}

我怎么做的方法调用一个的ArrayList

How do I do a method call for an ArrayList?

下面是我的code:

import java.util.*;

public class Test2{

    public static int[] toArray(ArrayList<Integer>a){
        int len = a.size();
        int []b = new int[len];
        for(int i = 0; i<len; i++){
            b[i] = a.get(i);
        }
     return b;    

    }
}

现在我想测试它在BlueJ的,我应该在下面的对话框中键入?

Now I want to test it in BlueJ, what should I type in the following dialog box?

推荐答案

您需要创建的ArrayList 的一个实例传递给你的方法,当你调用它。与您的项目在主BlueJ的窗口打开,单击工具菜单,然后点击使用库类...,然后从类别选择的java.util.ArrayList 菜单。也可以选择从显示的列表中的无参数的构造函数,然后单击确定。

You need to create an instance of ArrayList to pass to your method when you call it. With your project open in the main BlueJ window, click on the Tools menu, then on "Use Library Class...", then select java.util.ArrayList from the Class menu. Also select the no-argument constructor from the list that appears, then click Ok.

BlueJ的将显示另一个对话框,要求您为实例的名称和为的ArrayList 类型参数。输入一个名称和整数的类型参数。

BlueJ will then display another dialog asking you for a name for the instance and for a type parameter for the ArrayList. Enter a name and Integer for the type parameter.

单击确定后,新的的ArrayList 实例将在主BlueJ的窗口底部会出现在替补席上对象的区域。

After you click Ok, the new ArrayList instance will appear in the object bench area at the bottom of the main BlueJ window.

当你右击新实例,BlueJ的显示,可以在其上调用的方法的菜单。选择布尔加(整数)方法的几十倍一些值添加到该实例。

When you right click on the new instance, BlueJ will display a menu of methods that can be called on it. Select the boolean add(Integer) method a few times to add some values to the instance.

最后,当您在您的测试类右键点击并调用的toArray 方法,你可以进入的ArrayList的名称实例把它作为参数传递给你的方法。

Finally, when you right click on your test class and call the toArray method, you can enter the name of the ArrayList instance to pass it as the argument to your method.

方法调用的结果被显示在对话框

The results of the method call are displayed in a dialog.

点击检查按钮来查看 INT 数组的内容传回您的方法,或者点击Get按钮将其添加到该对象板凳上。

Click the Inspect button to view the contents of the int array returned from your method, or click the Get button to add it to the object bench.

这篇关于我如何在BlueJ的一个ArrayList输入参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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