This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Associate Certification (SCJA,OCAJ 5/6) and the fly likes related to best practice Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Associate Certification (SCJA,OCAJ 5/6)
Bookmark "related to best practice" Watch "related to best practice" New topic
Author

related to best practice

vasu chowdary
Ranch Hand

Joined: Mar 15, 2008
Posts: 89
Hi,

I have small doubt about ArrayList. As a part of the webservice response object i get the ArrayList where i can find exactly 3(not more ,not less and not null) objects in that list.Based on the 1st object value i have to populate another object and based on 2nd object i have to populate another object.So my question is instead of writing below logic


can i directly access the object based on the index like below
>
Akhilesh Trivedi
Ranch Hand

Joined: Jun 22, 2005
Posts: 1526
Why not?


Keep Smiling Always — My life is smoother when running silent. -paul
[FAQs] [Certification Guides] [The Linux Documentation Project]
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4343
    
    8

Just remember that it's zero-indexed, so use arrayList.get(0), etc.
James Boswell
Bartender

Joined: Nov 09, 2011
Posts: 1012
    
    5

You mean:
vasu chowdary
Ranch Hand

Joined: Mar 15, 2008
Posts: 89
yes i mean
arrayList.get(0);
arrayList.get(1);
arrayList.get(2);

i heared that this not the best practice.is it correct?
Akhilesh Trivedi
Ranch Hand

Joined: Jun 22, 2005
Posts: 1526
vasu chowdary wrote:...webservice response object i get the ArrayList


Think why it is ArrayList and not an array?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: related to best practice
 
Similar Threads
use of casting
Clarification On TypeCasting of ArrayList in Java
Help with Arrays and ArrayLists
Retrieve empl from an arraylist
if statement (using BlueJ) and equalsIgnoreCase