如何在 java 中的第三个斜杠后获取字符串

How to fetch string after the third slash in java

我正在尝试获取第三个斜线后的字符串。但我不知道该怎么做。我用过拆分,但这不是我想要的。

for(String obj2: listKey.getCommonPrefixes()){
    Map<String, String> map = new HashMap<String, String>();
    String[] id = obj2.split("/");
    if (id.length > 3) {
        String name = id[3];
        map.put("id", name);
        map.put("date", "null");
        map.put("size", String.valueOf(obj2.length()));
        keys.add(map);
    }
}

id[3] 只给我 id[3] 但我想要第三个斜杠后的所有内容?我该怎么做?

你可以替换

 String[] id = obj2.split("/");

来自

 String[] id = obj2.split("/", 4);

来自javadoc :

The limit parameter controls the number of times the pattern is applied and therefore affects the length of the resulting array. If the limit n is greater than zero then the pattern will be applied at most n - 1 times, the array's length will be no greater than n, and the array's last entry will contain all input beyond the last matched delimiter. If n is non-positive then the pattern will be applied as many times as possible and the array can have any length. If n is zero then the pattern will be applied as many times as possible, the array can have any length, and trailing empty strings will be discarded.