• Post Reply Bookmark Topic Watch Topic
  • New Topic

explode() in Java?  RSS feed

 
Dave Comeau
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
In PHP, there is a native function called explode, and it works like this.

This would output 123.
Is there anything similar to this function in Java? Just wanted to ask before I wrote it myself. I checked out java.lang.string methods, but didn't see anything. Maybe I'm looking in the wrong place.
Thanks in advance - Dave
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Make sure you're using JDK 1.4, and you can use the split() method in String:
[code] String input = "1,2,3";
String[] array = input.split(",");
 
Dave Comeau
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks!
I have an older book I was using, Java 1.1, which explains why I didn't find the split method.
I should buy a newer book.
Thanks again.
 
Cory Wilkerson
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To those not on the 1.4 platform, have a look at the StringTokenizer class:
 
Vinod Vinu
Ranch Hand
Posts: 217
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use like this :-

 
Pushkar Choudhary
Rancher
Posts: 425
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vinod, while we appreciate anyone answering the questions here, the one you have answered is about 8 years old and I'm quite sure the OP is not looking for the answer anymore. DontWakeTheZombies.
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
... not to mention that the same answer was already given by Jim Yingst 7 years ago. It pays to read the full conversation.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!