Results 1 to 2 of 2
  1. #1
    eva
    eva is offline Member
    Join Date
    Dec 2007
    Posts
    49
    Rep Power
    0

    Default How to get part of a String?

    I have following code which produces the required output:
    Java Code:
    String fileNameWithExt = "interface_for_database_18sep07.txt";
    String fileName = fileNameWithExt.substring(0, 30);
    System.out.println(fileName);
    Output:

    Java Code:
    interface_for_database_18sep07
    The point is, I have mentioned the ending index of the string in substring(…) method. How can I make it a bit flexible because the filename can change.

    java.lang.StackOverflowError

    I have written a recursive module and I get java.lang.StackOverflowError. I got some output before this exception. I want to know after how much iteration this exception is raised. Wont Java compiler identify this recursive statement at compile time?

    - PEACE

  2. #2
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    9

    Default

    Java Code:
    String fileNameWithExt = "interface_for_database_18sep07.txt";
    int dot = fileNameWithExt.indexOf(".");
    String fileName = fileNameWithExt.substring(0, dot);
    System.out.println(fileName);
    I want to know after how much iteration this exception is raised.
    Depends on how you have set up your method. I would try to use some println statements to track what you think should be happening as it recurses.
    Wont Java compiler identify this recursive statement at compile time?
    Probably not; depends on what you wrote. Your code can compile okay and create all kinds of problems at runtime.

Similar Threads

  1. Inventory part 2 help please
    By badness in forum New To Java
    Replies: 1
    Last Post: 12-12-2007, 07:51 AM
  2. Help with mathematical part in java
    By lenny in forum Advanced Java
    Replies: 3
    Last Post: 08-09-2007, 01:55 PM

Posting Permissions

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