Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder
    Join Date
    Aug 2004
    Posts
    111
    Thanks
    0
    Thanked 0 Times in 0 Posts

    java equivalent to php explode

    What function in java is equivalent to the php explode function?

  • #2
    Regular Coder
    Join Date
    Apr 2005
    Location
    Folsom, CA
    Posts
    115
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I am gonna go ahead and assume you are working with server-side programming in JAva maybe? Are you using Servlets or JSPs? I worked with Servlets before and learning JSPs right now so I might be able to help if you could describe the functionality of explde in PHP.

  • #3
    Regular Coder
    Join Date
    Apr 2005
    Location
    Folsom, CA
    Posts
    115
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hey I just did a simple google search and found maybe what you are looking for would be the StringTokenizer class or the split method in the String class. That would be my suggestion if I am not waaaaaaaaaaaaay off of what you are asking. CHeers!

  • #4
    Regular Coder
    Join Date
    Dec 2003
    Posts
    367
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yup, String.split() will probably do (it doesn't have the limit optional parameter).

    Java Tip: You need to do something with strings, look for classes that have "string" in their name.

    shmoove

  • #5
    New to the CF scene
    Join Date
    Feb 2008
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    split is similar

    String str = "Madrid,Paris,London";
    String[] tokens = str.split(",")

    -------------------------------------

    tokens[0] = "Madrid";
    tokens[1] = "Paris";
    tokens[2] = "London";

    -------------------------------------

  • #6
    New to the CF scene
    Join Date
    Jun 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Use org.apache.commons.lang.StringUtils

    The problem with String.split() is that it uses a greedy regex match, so if some of your tokens are empty strings, it will drop them. If you want to preserve empty strings, use this method:

    StringUtils.splitPreserveAllTokens(String str, char separatorChar)


  •  

    Posting Permissions

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