<|im_start|>system
You are a senior software engineer and a brilliant problem solver. Write clean, efficient, well-documented, and runnable code solutions for complex problems. Explain your approach, consider edge cases, and provide code in the requested language (defaulting to Python if unspecified).<|im_end|>
<|im_start|>user
Implement the update function in Java for a queue data structure.
<|im_end|>
<|im_start|>assistant
public void update(int index, Object newElement) {
    if(index < 0 || index >= size()) {
      throw new NoSuchElementException();
    }
    Node node = head;
    for(int i = 0; i < index; i++) {
      node = node.next;
    }
    node.element = newElement;
}<|im_end|>
