Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-02-2008, 11:53 AM
Senior Member
 
Join Date: Nov 2007
Posts: 115
ravian is on a distinguished road
Indexing starting with 1
Indexing in Java starts with 0.

I am working in an application where I need it to start with 1. I know this can be done by subtracting 1 simply. For instance, if I want to fetch the 3rd item, it will be:

Code:
array[3-1];
Is there some pattern for this? I mean whats is the best way of achieving this.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 01-02-2008, 12:05 PM
roots's Avatar
Moderator
 
Join Date: Jan 2008
Location: Dallas
Posts: 263
roots is on a distinguished road
If it's number (like 3 above) your approach is the simple and best approach. In variables (index variables) subtract it by one first before the array operation.

There is no best way though .. i would go over line by line making every thing correct..
__________________
dont worry newbie, we got you covered.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 01-02-2008, 01:19 PM
Senior Member
 
Join Date: Nov 2007
Posts: 115
ravian is on a distinguished road
Thanks roots.

nice signature
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 01-04-2008, 01:30 PM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,412
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Roots is correct. In such a case do all the indexing operation with a temp value before doing the array operations.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 01-04-2008, 02:03 PM
rpwtdj's Avatar
Member
 
Join Date: Dec 2007
Posts: 15
rpwtdj is on a distinguished road
Send a message via MSN to rpwtdj
Maybe you can wrap your array in a new class.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Lucene Re-Indexing connect2srinath Lucene 1 05-11-2008 07:35 PM
Help, starting with java mathias New To Java 2 08-15-2007 09:15 AM
just starting specbailey New To Java 23 08-14-2007 01:25 AM


All times are GMT +3. The time now is 01:15 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org