Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Read String to List<Integer> and back

  1. #1
    Senior Member
    Join Date
    Jul 2013
    Location
    Europe
    Posts
    666
    Thanks
    0
    Thanked 121 Times in 105 Posts

    Default Read String to List<Integer> and back

    Hi there,

    I am looking for a good and reliable library to read a string to construct a list of Integers, Doubles, Booleans, etc.
    This library should be robust enough to handle faulty input from an inexperienced user.

    Example:
    input: "1, 2, 3, 4"
    output List<Integer> [1, 2, 3, 4]

    input: "1, 2, 3.6, 4"
    output List<Double> [1.0, 2.0, 3.6, 4.0]

    input: "true, true, false"
    output List<Boolean> [true, true, false]

    input: "[1, 2, 3]"
    output List<Integer> [1, 2, 3]

    input: "(1, 2, 3)"
    output List<Integer> [1, 2, 3]


    It would be really nice if such a library would already exist. Would save me an hour of writing it myself.
    So yeah, if you know of any reliable library please let me know, I would really appreciate.
    Thank you very much.


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Read String to List<Integer> and back

    Thread moved from 'What's wrong with my code'.

    Take a look at JSON (don't let the javascript in the acronym fool you, as it is just a simple way of representing variables, arrays, and maps as text). json.org has a library that reads/writes objects to and from String's. For instance, the JSONArray class can be used to do just that.

    JSON in Java

  3. #3
    Senior Member
    Join Date
    Jul 2013
    Location
    Europe
    Posts
    666
    Thanks
    0
    Thanked 121 Times in 105 Posts

    Default Re: Read String to List<Integer> and back

    Well thank you, I will take a look at it.

Similar Threads

  1. Return type of converting integer to string for linked list
    By jcfor3ver in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 22nd, 2013, 07:37 PM
  2. Replies: 3
    Last Post: October 5th, 2013, 09:14 AM
  3. Replies: 6
    Last Post: June 3rd, 2013, 04:57 AM
  4. How to change a String value into a number and then back into a String.
    By javapenguin in forum What's Wrong With My Code?
    Replies: 5
    Last Post: November 18th, 2011, 01:43 PM
  5. how to read an integer of DOUBLE datatype with type casting
    By amr in forum What's Wrong With My Code?
    Replies: 3
    Last Post: December 14th, 2010, 03:03 PM