Java – is there a simpler way to split / rebuild strings?

I'm currently using string Split (""), as follows:

String[] tmp = props.get(i).getFullName().split("\\.");
String name = "";
for(int j = 1; j < tmp.length; j++){
    if(j > 1){
        name = name + "." + tmp[j];
    }
    else
        name = name + tmp[j];
}

My string format is first second. third … n-1. n. What I really need to do is get rid of it first

Solution

I can use it

String s = "first.second.third...n-1.n";
s = s.substring(s.indexOf('.')+1);
// or
s = s.replaceFirst(".*?\\.","");
System.out.println(s);

print

second.third...n-1.n
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>