如何设置数组维长数 [英] How to set array dimension to long number

查看:123
本文介绍了如何设置数组维长数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在Java中,从数据库表中获取其内容创建一个的JTable 。这可能是行数可能会超过Java中的 INT 数据类型作为数据库表的主键的能力已被设置为 BIGINT 的数据类型(SQL Server 2008中)。

I have created a jtable in Java that fetches its contents from a database table. It is possible that number of rows might exceed the capacity of the int datatype in Java as the database table's primary key has been set to bigint datatype (SQL Server 2008).

我想要做的就是创建一个二维数组,将持有 N ,其中 N 是数据行数据类型。这种数据的阵列将被传递到JTable中的典范。我试图声明数组对象不提供行号,只提供数列,但它给了语法错误。可能是我作出声明的方法是错误的。如果有这种类型声明的任何方法,那么请告诉我的语法或者如果没有的话,请告诉我该解决方案来解决它。该阵列持有对象类型的数据(即它是一个对象[] 阵列)。

What I want to do is create a 2D array that would hold n rows of data where n is of long datatype. This array of data would be passed to jtable's model. I tried to declare array object without providing rows number and providing columns number only but it gave syntax error. May be I made a mistake in declaration method. If there is any method of such type declaration then please tell me the syntax or if not then please tell me the solution to solve it. The array is holding data of Object type (i.e. it is an Object[] array).

推荐答案

您不能设置一个数组的大小比 Integer.MAX_VALUE的越大,的 Java的规范有以下地说:

You can't set an array to a size larger than Integer.MAX_VALUE, the java specs has the following to say:

数组必须由int类型索引;短,字节或字符值也可以用作索引值,因为它们进行一元数值升级(§5.6.1),并成为int值中

Arrays must be indexed by int values; short, byte, or char values may also be used as index values because they are subjected to unary numeric promotion (§5.6.1) and become int values.

这是试图用一个编译时错误很长的索引值结果访问数组组成部分。

An attempt to access an array component with a long index value results in a compile-time error.

因此​​,你不能创建一个大小不是整数的MAXVALUE较大的数组。该为什么我不知道,但我的猜测是,它已经是与优化。如此看来,你必须去与的ArrayList

Thus you can't create an array with a size larger than the maxvalue of integers. The why I don't know, but my guess is that it has something to do with optimization. So it seems that you have to go with an ArrayList.

这篇关于如何设置数组维长数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆