简体   繁体   中英

Queues of Arrays Java

I'm working on a program that orders jobs for three different people, so I used queues because the jobs need to be done first in, first out. The jobs are arrays storing three different strings. This is the relevant code I have at the moment.

Queue<String[]> MMT1Jobs  = new LinkedList<String[]>();
Queue<String[]> MMT2Jobs  = new LinkedList<String[]>();
Queue<String[]> MMT3Jobs  = new LinkedList<String[]>();
//job array layout should look like this [registration number][grid reference][who is assign to the job]
String[] MMT1CurrentJob = new String[3];
String[] MMT2CurrentJob = new String[3];
String[] MMT3CurrentJob = new String[3];
String[] MMT1LastJob = new String[3];
String[] MMT2LastJob = new String[3];
String[] MMT3LastJob = new String[3];
String[] justScanned = new String[3];
//check if there is any Jobs open
File jobsOpenFile = new File("JOBS-OPEN.txt");
if(jobsOpenFile.exists())
{
  //File exists
  Scanner jobsFile = new Scanner(jobsOpenFile);
  while(jobsFile.hasNext == true)
  {
    justScanned[1] = jobsFile.next();//registration number
    justScanned[2] = jobsFile.next();//grid reference
    justScanned[3] = jobsFile.nextLine();//who is assigned and end of line
    //assign who get what jobs
    if(justScanned[3].equals("1"))
    {
      MMt1Jobs.add(justScanned[]);//error here
    }
    else if(justScanned[3].equals("2"))
    {
      MMt2Jobs.add(justScanned[]);//error here
    }
    else
    {
      MMt3Jobs.add(justScanned[]);//error here
    }
  }
}

I'm currently getting "error: '.class' expected" on the lines that I've marked. Sorry if this is a simple fix but I'm new to java. Thanks in advance.

I believe you don't need the array brackets( [] ) in your errornous statements:

  MMt1Jobs.add(justScanned[]);//error here

replace this with

  MMt1Jobs.add(justScanned)

No need for that extra [] .

[] is a syntax part of array declaration time to specify length of array .

Therefore, you need not use it while adding the array to a list . Just use variable name.

可能是一个非常愚蠢的事情要指出,但如果这是复制粘贴,那么你的“MMt1Jobs”不应该是“MMT1Jobs”,首都是“t”吗?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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