小编Del*_*ley的帖子

Recursion vs For循环 - Factorials,Java

获得因子(循环与递归)的这两种方法中的哪一种更有效/更快?如果那个可以改进,怎么样?

语言:Java

private static long factrecur(int n) {
    if (n == 0) {
        return 1;
    }
    else {
        return n * factrecur(n-1);
    }

}

private static long factloop(int a) {
    long total = 1;
    for (int b=a;b>=1;b--) {
        total *= b;
    }
    return total;
}
Run Code Online (Sandbox Code Playgroud)

java recursion for-loop

10
推荐指数
1
解决办法
7562
查看次数

Java - 不推荐的方法 - 怎么办?

我正在学习一系列Java教程,试图学习它.我对教程72有疑问.

链接:http://www.youtube.com/watch?v = 9z_8yEv7nIc&feature = relmfu

在视频的7:02,写下了这个陈述.但是,此方法已在Java 1.7中弃用.

RightList.setListData(LeftList.getSelectedValues());

Eclipse返回以下错误:

    Object[] javax.swing.JList.getSelectedValues()
    getSelectedValues
    @Deprecated
    public Object[] getSelectedValues()
    Deprecated. As of JDK 1.7, replaced by getSelectedValuesList()
    Returns an array of all the selected values, in increasing order based on their indices in the list.
    Returns:
    the selected values, or an empty array if nothing is selected
    See Also:
    isSelectedIndex(int), getModel(), addListSelectionListener(javax.swing.event.ListSelectionListener)
Run Code Online (Sandbox Code Playgroud)

但这会返回一个错误,说'方法setListData(Object[]) in the type JList is not applicable for the arguments (List)'.

更换上述声明的正确方法是什么?


另外,我想借此机会提出另一个不相关的问题.最好在方法之外初始化变量,如下所示: …

java variables deprecated jlist

4
推荐指数
1
解决办法
7799
查看次数

标签 统计

java ×2

deprecated ×1

for-loop ×1

jlist ×1

recursion ×1

variables ×1