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 4 of 4

Thread: Splitting operators

  1. #1
    Junior Member
    Join Date
    Feb 2018
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Splitting operators

    I am wondering why this code works on C# but not on Java?
    It gives me an error in split function that it can only take strings
    Should I change the separators to String
    so it will be like this

                String separators = " .,:\t"

                char[] separators = { '  ', ',', '.', ':', '\t' };
                String[] words;
                words = value.split(separators);   //Value is a string passed inside this function

    The program basically takes a name like, "Mr. John Doe" and it will ignore the . and white space

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,223
    Thanks
    53
    Thanked 2,385 Times in 2,339 Posts

    Default Re: Splitting operators

    Should I change the separators to String
    Its best to read the API doc for the methods you use and see what the requirements are.

    If you have any questions about what it says in the API doc, copy the text here and ask the question.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3

    Default Re: Splitting operators

    Splits a string into parts based on a regex and stores it into an String array. The regex is a string used to determine where to split the bigger string. For example, to extract individual words from a sentence, a space would be used as a regex.

  4. #4
    Member
    Join Date
    Dec 2013
    Location
    Honolulu
    Posts
    83
    Thanks
    1
    Thanked 4 Times in 2 Posts

    Default Re: Splitting operators

    Do you have the whole program to this task? I can see where and how it might be used, but don't know exactly what class files or packages are imported.

Similar Threads

  1. on unary operators
    By tappetivamsi in forum What's Wrong With My Code?
    Replies: 4
    Last Post: December 28th, 2013, 07:12 AM
  2. Operators
    By Skybear in forum What's Wrong With My Code?
    Replies: 7
    Last Post: December 11th, 2012, 12:53 PM
  3. Help with logical operators
    By BiaxialPainter in forum What's Wrong With My Code?
    Replies: 2
    Last Post: April 11th, 2012, 12:35 AM
  4. Logical Operators
    By truebluecougarman in forum Java Theory & Questions
    Replies: 3
    Last Post: January 22nd, 2011, 05:26 PM
  5. Need Help with Operators/ logic
    By codekiller in forum What's Wrong With My Code?
    Replies: 5
    Last Post: October 3rd, 2010, 09:25 AM

Tags for this Thread