# 神奇的split()

* 抖音：<https://v.douyin.com/iUBMnaLp/>
* B站：<https://www.bilibili.com/video/BV1AemXY7Exj/>

我发现这 split()

在Java和Js里的表现不一样哈

先看Java

我们用jshell

我们用a b三个逗号split

然后一个参数

大家看啊

它返回两个

我们再看Js哈

还是a b

然后split

大家看它就是五个

它把每一个中间当成一个空字符串了

然后其实它们都有第二个参数

比如我们看Js啊

我们传

它就只要前两个

然后我们传

大家看他就前三个

这很简单

如果我们传0呢

他就一个也没有

我们传-1呢

就是最初的效果

这都很容易理解

我们再看Java哈

Java就比较有意思

我们还是这个

然后我们加一个参数-

大家看这个就是我们想要的效果

5个跟Js保持一致了

但是如果我们传

大家注意啊

它就会生成两个

但是它第一个是a

第二个是b

逗号逗号

逗号也就是说它把这一个当成逗号

然后后面这四个当成一个字符串了

我们再看

大家看a b

然后两个逗号

以此类推

我们再看

这样我们再看五

五就跟刚才一样了


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://sunzsh.gitbook.io/xiaoshan.bug/shen-qi-de-split.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
