Results 1 to 5 of 5
  1. #1
    ravian is offline Senior Member
    Join Date
    Nov 2007
    Posts
    115
    Rep Power
    0

    Default 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:

    Java Code:
    array[3-1];
    Is there some pattern for this? I mean whats is the best way of achieving this.

  2. #2
    roots's Avatar
    roots is offline Moderator
    Join Date
    Jan 2008
    Location
    Dallas
    Posts
    293
    Rep Power
    7

    Default

    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.

  3. #3
    ravian is offline Senior Member
    Join Date
    Nov 2007
    Posts
    115
    Rep Power
    0

    Default

    Thanks roots.

    nice signature :D

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    Roots is correct. In such a case do all the indexing operation with a temp value before doing the array operations.

  5. #5
    rpwtdj's Avatar
    rpwtdj is offline Member
    Join Date
    Dec 2007
    Posts
    15
    Rep Power
    0

Similar Threads

  1. Lucene Re-Indexing
    By connect2srinath in forum Lucene
    Replies: 1
    Last Post: 05-11-2008, 06:35 PM
  2. Help, starting with java
    By mathias in forum New To Java
    Replies: 2
    Last Post: 08-15-2007, 08:15 AM
  3. just starting
    By specbailey in forum New To Java
    Replies: 23
    Last Post: 08-14-2007, 12:25 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •