Home > Back-end >  ArrayList an array of problems
ArrayList an array of problems

Time:11-27

New an arraylist no default length, from a database query to a record in the list, the get (0) error when an array,,,

CodePudding user response:

Definition of course can not set the array length: such as int [] a; But to initialize it to become a real sense of array must be set length: int [] a=new int [10]. 这时就只能改变数组里的数值而不能改变它的长度了.Java是一门面向对象编程语言,不仅吸收了C++语言的各种优点,还摒弃了C++里难以理解的多继承,指针等概念,因此Java语言具有功能强大和简单易用两个特征,Java语言作为静态面向对象编程语言的代表,极好地实现了面向对象理论,允许程序员以优雅的思维方式进行复杂的编程,扩展资料:1.简单性,Java看起来设计得很像C++,但是为了使语言小和容易熟悉,设计者们把C++语言中许多可用的特征去掉了,这些特征是一般程序员很少使用的,例如,Java不支持go to语句,代之以提供break和continue语句以及异常处理,Java还剔除了C++的操作符过载(overload)和多继承特征,并且不使用主文件,免去了预处理程序,因为Java没有结构,数组和串都是对象,所以不需要指针,Java能够自动处理对象的引用和间接引用,实现自动的无用单元收集,使用户不必为存储管理问题烦恼,能更多的时间和精力花在研发上,2.面向对象,Java是一个面向对象的语言,对程序员来说,这意味着要注意应中的数据和操纵数据的方法(method),而不是严格地用过程来思考,在一个面向对象的系统中,类(class)是数据和操作数据的方法的集合,数据和方法一起描述对象(object)的状态和行为,每一对象是其状态和行为的封装,类是按一定体系和层次安排的,使得子类可以从超类继承行为,在这个类层次体系中有一个根类,它是具有一般行为的类,Java程序是用类来组织的,Java还包括一个类的扩展集合,分别组成各种程序包(Package),用户可以在自己的程序中使用,例如,Java提供产生图形用户接口部件的类(java.awt包),这里awt是抽象窗口工具集(abstract windowing toolkit)的缩写,处理输入输出的类(java.io包)和支持网络功能的类(java.net包),3.分布性,Java设计成支持在网络上应用,它是分布式语言,Java既支持各种层次的网络连接,又以Socket类支持可靠的流(stream)网络连接,所以用户可以产生分布式的客户机和服务器,网络变成软件应用的分布运载工具,Java程序只要编写一次,就可到处运行,

CodePudding user response:

I this belongs to an ArrayList in the add a data and then get (0), an error rangecheck should be the problem of index, an error Java. Long. IndexoutofBoundsException

Index: 0 Size: 0

CodePudding user response:

Did you really add?

CodePudding user response:

Add success in it and see if it is null

CodePudding user response:

Look at the size of the ArrayList, whether from the database access did not add in

CodePudding user response:

My local run when there is no problem, the return value I see next is some, and then directly get (0) is an error, I am in a Linux environment to run, your local run is not an error,,,,

CodePudding user response:

Print the list arraylist initialization time is can not specify the length of it before adding the mechanism of expansion will determine whether expansion
  • Related