plz help

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pralu
    New Member
    • Mar 2008
    • 34

    plz help

    Code:
    class String1
    {
    	public static void main(String[] args)
    	{
    		String string = "hi this is alok kumar singh working in honeywell";
    		int start=10;
    		int end=25;
    		char buffer[] = new char[end-start];
    		string.getChars(start,end,buffer,0);
    		System.out.println(buffer);
    	}
    }

    in line : string.getChars (start,end,buff er,0);.... now in this if i specify 1 in place of 0 then its throwing the error of index out of bound can anyone explain me why so???
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by pralu
    Code:
    class String1
    {
    	public static void main(String[] args)
    	{
    		String string = "hi this is alok kumar singh working in honeywell";
    		int start=10;
    		int end=25;
    		char buffer[] = new char[end-start];
    		string.getChars(start,end,buffer,0);
    		System.out.println(buffer);
    	}
    }

    in line : string.getChars (start,end,buff er,0);.... now in this if i specify 1 in place of 0 then its throwing the error of index out of bound can anyone explain me why so???
    The reason is well laid out in the API docs.

    Comment

    • JosAH
      Recognized Expert MVP
      • Mar 2007
      • 11453

      #3
      Originally posted by pralu
      Code:
      class String1
      {
      	public static void main(String[] args)
      	{
      		String string = "hi this is alok kumar singh working in honeywell";
      		int start=10;
      		int end=25;
      		char buffer[] = new char[end-start];
      		string.getChars(start,end,buffer,0);
      		System.out.println(buffer);
      	}
      }

      in line : string.getChars (start,end,buff er,0);.... now in this if i specify 1 in place of 0 then its throwing the error of index out of bound can anyone explain me why so???
      Do your (simple) math: that method attempts to get 'end-start' characters and
      store it in a buffer somewhere. Your buffer happens to be able to store 'end-start'
      characters; guess where the first character must be stored.

      kind regards,

      Jos (fourtytwo!)

      Comment

      • pralu
        New Member
        • Mar 2008
        • 34

        #4
        Originally posted by JosAH
        Do your (simple) math: that method attempts to get 'end-start' characters and
        store it in a buffer somewhere. Your buffer happens to be able to store 'end-start'
        characters; guess where the first character must be stored.

        kind regards,

        Jos (fourtytwo!)

        thanks for the help and i got it

        Comment

        Working...