current position:Home>A small problem about string []

A small problem about string []

2022-02-02 14:33:21 CSDN Q & A

package notebook;
import java.util.ArrayList;
public class NoteBook {
private ArrayListnotes= new ArrayList();

public void add(String r) {        notes.add(r);        }public void add (String r ,int location) {    notes.add(location,r);}public int getsize() {    return notes.size();}public String getnote(int index) {    return notes.get(index);}public void remove(int index) {        notes.remove(index);}public String[] list() {String [] a= new String[notes.size()];for (int i=0;i<notes.size();i++) {        a[i]=notes.get(i);    }            return a;}String []x=new String[10];for (int i=0;i<x.length;i++) {    x[i]=""+i;}System.out.println(x[10]);}

} Why are the last few lines exceeded after running length




Refer to the answer 1:

x[10] Across the border
The maximum subscript is 9




Refer to the answer 2:

copyright notice
author[CSDN Q & A],Please bring the original link to reprint, thank you.
https://en.primo.wiki/2022/02/202202021433194359.html

Random recommended