Results 1 to 5 of 5
  1. #1
    neveser is offline Member
    Join Date
    Nov 2012
    Posts
    40
    Rep Power
    0

    Default can you parse to get data for an array?

    can you parse to get data for an array?

    or is scanner the only way?

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default Re: can you parse to get data for an array?

    I know of no automatic plug in and parse to array. You need to write code for that. You may use a Scanner object for this, or any other object that will accept input.

  3. #3
    neveser is offline Member
    Join Date
    Nov 2012
    Posts
    40
    Rep Power
    0

    Default Re: can you parse to get data for an array?

    Thanks.
    I thought that was the case.

    I'm trying to use scanner to get input from a jTextField without much luck. Parsing was easy but it needs to go into an array, so no parsing.

    I have the line -

    Java Code:
    Scanner minutesIn = new Scanner(minutesField.getText());
    The problem is, I need to get the input into a double for the array and math to follow.

    I tired to add this line afterwards to turn the input into a double but it obviously doesn't work
    Java Code:
    double minutesIn = minutesIn.nextDouble();
    I guess I need to somehow combine these 2 lines so it works, just not sure how.

    EDIT:

    I've changed things a bit. I'm now using this line -
    Java Code:
    double minutesIn = Double.parseDouble(minutesField.getText());
    Now, I need to use the scanner on this to get it into my array.
    Problem is I have no idea how to do this.
    Last edited by neveser; 11-29-2012 at 01:41 AM.

  4. #4
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default Re: can you parse to get data for an array?

    I'm really confused by your question and subsequent post. Are you trying to tokenize an input, convert a String to a double, or what?

    Your final example using Double.parseDouble is the correct way to convert the String representation of a double into an actual double data type. What data type does your array hold? Most likely you just need to cast.

  5. #5
    neveser is offline Member
    Join Date
    Nov 2012
    Posts
    40
    Rep Power
    0

    Default Re: can you parse to get data for an array?

    Quote Originally Posted by quad64bit View Post
    I'm really confused by your question and subsequent post. Are you trying to tokenize an input, convert a String to a double, or what?

    Your final example using Double.parseDouble is the correct way to convert the String representation of a double into an actual double data type. What data type does your array hold? Most likely you just need to cast.
    The data needs to be a double. I did find out that the second example was the way to go. Now I'm just having trouble getting the 2 user inputs into a 2D array. The first input works fine but the second produces an error. Since it's a new problem, I made a seperate thread, Second number not getting into 2D array

Similar Threads

  1. Parse Data from Java Applet
    By ssh1091 in forum Java Applets
    Replies: 6
    Last Post: 02-27-2011, 04:28 AM
  2. How can I parse the data ?
    By krr in forum CLDC and MIDP
    Replies: 5
    Last Post: 08-21-2010, 04:01 PM
  3. Using Tokenizer to parse file data--CODE
    By Cylab in forum Java Software
    Replies: 0
    Last Post: 07-26-2010, 12:48 PM
  4. add data into an array
    By mispeed in forum New To Java
    Replies: 9
    Last Post: 11-08-2007, 04:53 AM
  5. Add data to an array
    By adlb1300 in forum New To Java
    Replies: 8
    Last Post: 11-05-2007, 03:01 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
  •