爆炸和内爆(就像PHP)在Java中 [英] Explode and Implode (just like PHP) in Java

查看:145
本文介绍了爆炸和内爆(就像PHP)在Java中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Java中是新的,虽然有在PHP中一个很好的经验,并寻找完美的替代品在Java爆炸,爆(在PHP可用)的功能。

I am new in Java although had a good experience in PHP, and looking for perfect replacement for explode and implode (available in PHP) functions in Java.

我已经用Google搜索相同,但不满意的结果。
任何人有我的问题将是AP preciated很好的解决方案。

I have Googled for the same but not satisfied with the results. Anyone has the good solution for my problem will be appreciated.

推荐答案

借助 Javadoc文档字符串显示, String.split()就是你在考虑找什么,以爆炸

The Javadoc for String reveals that String.split() is what you're looking for in regard to explode.

Java不包括的加盟等内爆。而不是包括一个简单的功能,一个巨大的对外依存度为其他答案建议,你可能只想写code的几行。有多种方式来实现这一目标;使用的StringBuilder 是一个:

Java does not include a "implode" of "join" equivalent. Rather than including a giant external dependency for a simple function as the other answers suggest, you may just want to write a couple lines of code. There's a number of ways to accomplish that; using a StringBuilder is one:

String foo = "This,that,other";
String[] split = foo.split(",");
StringBuilder sb = new StringBuilder();
for (int i = 0; i < split.length; i++) {
    sb.append(split[i]);
    if (i != split.length - 1) {
        sb.append(" ");
    }
}
String joined = sb.toString();

这篇关于爆炸和内爆(就像PHP)在Java中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆