Results 1 to 3 of 3
Like Tree1Likes
  • 1 Post By jim829

Thread: whats happening with this string is it funny?

  1. #1
    vknehra10 is offline Senior Member
    Join Date
    Dec 2016
    Posts
    103
    Rep Power
    0

    Default whats happening with this string is it funny?

    i made a string "computer" its total index is

    c=0
    o=1
    m=2
    p=3
    u=4
    t=5
    e=6
    r=7

    right?

    but when i trying to find indexOf usng lastIndexOf like below
    Java Code:
    String s="computer";
    int i=s.lastIndexOf("uter",10);   //total indexes are 7...
    System.out.println("blaahh"+i);
    output : blaahh 4 // why total index are 7 and compiler starts from 10 and give me correct answer what's that...

    thanks

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: whats happening with this string is it funny?

    Assuming I understand your question, I also assume you did not read the API documentation for String().

    From the String.lastIndex() api.

    "There is no restriction on the value of fromIndex. If it is greater than or equal to the length of this string, it has the same effect as if it were equal to one less than the length of this string: this entire string may be searched. If it is negative, it has the same effect as if it were -1: -1 is returned."

    Regards,
    Jim
    vknehra10 likes this.
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  3. #3
    vknehra10 is offline Senior Member
    Join Date
    Dec 2016
    Posts
    103
    Rep Power
    0

Similar Threads

  1. What is happening here?
    By nakkim in forum New To Java
    Replies: 4
    Last Post: 02-12-2014, 08:25 AM
  2. whats the need of converting string to long
    By Jack_Tauson_Sr in forum New To Java
    Replies: 2
    Last Post: 01-11-2013, 08:48 PM
  3. I don't know what is happening
    By Fred1 in forum New To Java
    Replies: 2
    Last Post: 04-28-2011, 12:21 AM
  4. Database String... whats wrong?
    By neosnokia in forum New To Java
    Replies: 10
    Last Post: 06-05-2009, 01:40 PM

Tags for this Thread

Posting Permissions

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