Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / December 2007

Tip: Looking for answers? Try searching our database.

Obj In array as int

Thread view: 
mnml - 05 Dec 2007 08:04 GMT
Hi,
I am trying to make a if loop using a Int value contained in an Array
'array2D[a][a]'

            if(array2D[a][a]==0)
            dosomething();

I would like to know how I can define the content as an Integer in
that case;
The error message:

./myDisplay.java:52: incomparable types: java.lang.Object and int
                       if(array2D[a][a]==0)
                                       ^

Thanks
GArlington - 05 Dec 2007 12:05 GMT
> Hi,
> I am trying to make a if loop using a Int value contained in an Array
[quoted text clipped - 12 lines]
>
> Thanks

Are you trying to make a 2D array of Integer objects
Integer [][] array2D = new Integer[a][b];
or 2D array of int (primitive data type)
int[][] array2D = new int[a][b];
Lew - 05 Dec 2007 14:59 GMT
mnml <rdelsa...@gmail.com> wrote:
>> Hi,
>> I am trying to make a if loop using a Int value contained in an Array
[quoted text clipped - 10 lines]
>>                         if(array2D[a][a]==0)
>>                                         ^

> Are you trying to make a 2D array of Integer objects
> Integer [][] array2D = new Integer[a][b];
> or 2D array of int (primitive data type)
> int[][] array2D = new int[a][b];

To the OP: Here's where an SSCCE
<http://www.physci.org/codes/sscce.html>
can be so very useful.

Notice that GArlington's question can only be answered by reference to the
code that you /didn't/ post.

An Integer or int array would've worked.

Another hint - the error message told you what was wrong.  You were comparing
an Object to an int.  What would have been comparable, if not Object to int?

Signature

Lew

mnml - 05 Dec 2007 16:53 GMT
> > Hi,
> > I am trying to make a if loop using a Int value contained in an Array
[quoted text clipped - 17 lines]
> or 2D array of int (primitive data type)
> int[][] array2D = new int[a][b];

thanks you.
GArlington - 05 Dec 2007 12:06 GMT
> Hi,
> I am trying to make a if loop using a Int value contained in an Array
[quoted text clipped - 12 lines]
>
> Thanks

If is NOT a loop...
Roedy Green - 06 Dec 2007 13:00 GMT
>Hi,
>I am trying to make a if loop using a Int value contained in an Array
>'array2D[a][a]'
>
>            if(array2D[a][a]==0)
>            dosomething();

see http://mindprod.com/jgloss/array.html

To compare, without auto unboxing, see
http://mindprod.com/applet/converter.html
Signature

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.