小编fki*_*s15的帖子

ArrayList对象

我正在使用ArrayList对象来创建一个类型为employee的员工对象...我实现了这个类似乎工作,但我的问题是,当我将员工插入ArrayList时,它自动不插入它.这是为什么?

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author
 */

import java.util.*;

class Employee {

    private String fname;
    private String lname;



    public Employee (String fname, String lname){
        this.fname = fname;
        this.lname = lname;
    }

    public Employee (){
    }

    public String getLastName(){
            return this.lname;
    }

    public void setLastName(String lname){
            this.lname = lname;
    }

    public String getFirstName(){
        return this.fname;
    }

    public void setFirstName (String fname){
        this.fname = …
Run Code Online (Sandbox Code Playgroud)

java arraylist

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

IndexOutOfBoundsException为什么?

好的...我正在尝试实现我自己的bin排序版本,通常称为桶排序.我运行程序,我得到一个indexOutOfBounds错误.我不知道为什么.有人可以解释原因.请注意,binsort算法尚未完成.Int n是数组的长度,m是由随机数生成器从0到100生成的列表的上限.

public static void binSort (int []array, int n, int m)
{
//create upperbounds
int x = m / 3;                    //33
int y = n - x;                    //67
int z = n;                        //100

int []temp1 = new int [n-1];
int []temp2 = new int [n-1];
int []temp3 = new int [n-1];

for (int i: array)
{
    if(array[i] < x)
    {
        temp1[i] = array[i];
    }
    else if(array[i] < y)
    {
        temp2[i] = array[i];
    }
    else
    {
        temp3[i] = array[i];     
    } …
Run Code Online (Sandbox Code Playgroud)

java sorting

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

标签 统计

java ×2

arraylist ×1

sorting ×1