Note that there are some explanatory texts on larger screens.

plurals
  1. POError while removing array element
    primarykey
    data
    text
    <p>I have new arraylist, 1 arraylist which has 10 customer already inserted. I'm running a loop which picks a random customer from the arraylist and adds it into the 2nd arraylist. However, I'm getting duplicates when I insert customer into the 2nd arraylist. So when the loop runs after adding the customer into the 2nd arraylist it will remove it from the 1st arraylist.</p> <p>However, when it runs I get an error: <code>Intervals error: java.lang.IndexOutOfBoundsException: Index: 7, Size: 7</code></p> <pre><code>ArrayList&lt;String&gt; customer = new ArrayList&lt;String&gt;(Arrays.asList(list)); int customerlist = customer.size(); while (line.isEmpty()) { for (int x = 0; x &lt; customerlist; x++ ) { try { Thread.sleep(intervals * 1000); //Sleep method to hold the arrival time by 1-2 seconds. int cus = (int) (Math.random() * customerlist); //Random customer is picked here. String new_cus = customer.get(cus); //New customer object is created ere. line.add(new_cus); //Customer objects are added to the empty LinkedList queue. customer.remove(cus); //For loop statement to outputting the queue. for (String s : line) { System.out.print("[" + s.toString() + " " + "]"); //Outputting each customer and using the ".name" method so customers are readable. } //Outputting the whole queue and stating who has joined the queue. System.out.println("\n" + "The queue has " + line.size() + " customers so far" + "\n" + new_cus.toString() + " Has Joined the Queue " + " &lt;=== WAITING" + "\n"); } catch(Exception e) //ERROR handler for sleep method. { System.out.println("Intervals error: " + e); //Outputting the ERROR message. System.exit(0); //If ERROR found exit system. } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload