java正则常用记录

1.   java中 字符串的某个字母是否有某个指定字符N  :   

for(int i=0;i<temp.length();i++){

  if( temp.get(i).substring(0,1).equals(N) ) {

}

例子:

List<String> temp = new ArrayList<String>();
temp.add("Node 1");  //0
temp.add("2 3");   //1
temp.add("3 4");   //2
temp.add("Node 2");  //3
temp.add("3 5");        //4
for(int i=0;i<temp.size();i++){
  if (temp.get(i).substring(0,1).equals("N")) {
    System.out.println(i);
  }
}
输入结果为:0 3

2.   去除字符串 最后的字符

  利用java中String类的substring()字符串截取方法 和length()求字符串长度方法即可

  public class Test {
    public static void main(String[] args) {
        String str = "abcdefg";
        System.out.println("截取最后一个字符串生成的新字符串为: " + str.substring(0,str.length()-1));
    }
  }
原文地址:https://www.cnblogs.com/andy-lehhaxm/p/9509800.html