小编Bob*_*Bob的帖子

错误:类型Selection中的方法sort(Comparable [])不适用于参数(int [])

这是我在尝试写出Selection排序时得到的错误.有人能指出我做错了什么.我的代码如下.谢谢!

    public class Selection
    {
        static void sort(Comparable[] a)
    {
    int N = a.length;
    for (int i = 0; i < N; i++)
    {
    int min = i;
     for (int j = i+1; j < N; j++)
     if (less(a[j], a[min]))
     min = j;
     exch(a, i, min);
     }
     }
     private static boolean less(Comparable v, Comparable w)
     { 
     return v.compareTo(w) < 0;   
     }
    private static void exch(Comparable[] a, int i, int j)
    { 
     Comparable temp = a[i];
     a[i] = a[j];
     a[j] = …
Run Code Online (Sandbox Code Playgroud)

java algorithm compiler-errors

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

如何用另一个数组列表的内容替换数组列表的内容?

我想用另一个数组的内容完全替换一个数组列表的内容。例如,

ArrayList<String> old = new ArrayList<String>();
ArrayList<String> newlist = new ArrayList<String>();
old.add("Hi");
old.add("World");
newlist.add("League")
newlist.add("OfLegends"):
old = newlist;
Run Code Online (Sandbox Code Playgroud)

当我尝试这样做时,它会执行这种奇怪的行为,其中数组列表的大小会随着更多元素而加倍。我不想要一个两倍于原始数组列表大小的数组列表,我只想用新的数组列表覆盖旧的数组列表,其中旧的和新的数组列表的内容是相同的。有没有办法在没有某种循环的情况下做到这一点,或者这是我唯一的选择?谢谢你

java oop arraylist

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

标签 统计

java ×2

algorithm ×1

arraylist ×1

compiler-errors ×1

oop ×1