How to get a string after the third braid in java

I am trying to get a string after the third slash. But I do not know how to do this. I used split, but that is not what I want.

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] gives me only id[3] , but I want everything after the third slash? How can i do this?

0
java substring indexof
source share
1 answer

You can replace

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

by

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

From javadoc :

The limit parameter controls the number of uses of the template and, therefore, affects the length of the resulting array. If the limit n is greater than zero, the pattern will be applied no more than n - 1 times, the length of the array will be no more than n, and the last element of the array will contain all the input data beyond the last matched separator. If n is not positive, the pattern will be applied as many times as possible, and the array can be of any length. If n is zero, the pattern will be applied as many times as possible, the array can be of any length, and the final empty lines will be discarded.

+8
source share

All Articles