The Artima Developer Community
Sponsored Link

Java Answers Forum
length variable in arrays

2 replies on 1 page. Most recent reply: Jun 9, 2005 5:34 AM by Kondwani Mkandawire

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 2 replies on 1 page
ali imran

Posts: 1
Nickname: aliimran90
Registered: Apr, 2005

length variable in arrays Posted: Apr 16, 2005 7:28 AM
Reply to this message Reply
Advertisement
When we call the new operator in java to create arrays which method is called and when we call the length variable of arrays in which class is it resident


nabakumar

Posts: 23
Nickname: nkmeitei
Registered: Jun, 2005

Re: length variable in arrays Posted: Jun 9, 2005 4:32 AM
Reply to this message Reply
When u declare a new array ,say whose members are of type "String"
we write like this : String[] str;

str is not an object of type String its simply an array whose members are of type String class

Then when you create an aray u give like this
str = new String[10];
The purpose of the new operator is to reserve memory for 10 members ,ie String in this case.

To get the size of the array we use str.length , here length is not a method ,length is a
property provided by the Java platform for all arrays

Kondwani Mkandawire

Posts: 530
Nickname: spike
Registered: Aug, 2004

Re: length variable in arrays Posted: Jun 9, 2005 5:34 AM
Reply to this message Reply
Thanks man, makes a lot of sense.
I was wondering when someone would respond to that
one coz when I saw the Q, I was dying to know the
response too...

(to the poster) good Q.

(to the responder) Thanks again...

Flat View: This topic has 2 replies on 1 page
Topic: installing netbeans Previous Topic   Next Topic Topic: Simple Difference

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use