现在的位置: 首页 > 综合 > 正文

equalsignorecase

2017年12月06日 ⁄ 综合 ⁄ 共 1130字 ⁄ 字号 评论关闭

equalsIgnoreCase
public boolean equalsIgnoreCase(String anotherString)将此 String 与另一个 String 进行比较,不考虑大小写。如果两个字符串的长度相等,并且两个字符串中的相应字符都相等(忽略大小写),则认为这两个字符串是相等的。
在忽略大小写的情况下,如果下列至少一项为 true,则认为 c1 和 c2 这两个字符相同。

这两个字符相同(使用 == 运算符进行比较)。
对每个字符应用方法 Character.toUpperCase(char) 产生相同的结果。
对每个字符应用方法 Character.toLowerCase(char) 产生相同的结果。

参数:
anotherString - 与此 String 进行比较的 String。
返回:
如果参数不为 null,且这两个 String 在忽略大小写时相等,则返回 true;否则返回 false。
另请参见:
equals(Object), Character.toLowerCase(char), Character.toUpperCase(char)

 

code

public class FindIdentical{ 
 static String[] saA    = {"Hiwa", "Sayonara", "Aaron","Golu","Saddam","Superman"}; 
 static String[] saB    = {"gwhgf", "ARIGATO", "Aami","Gou","Sadam","SuperMan","hiwa","Divz"}; 
 static boolean flag = false;  static String a; 
 public static void main(String[] args){   
  for (int i = 0; i < saA.length; ++i){     
   for(int j = 0; j < saB.length; ++j){       
    if (saA[i].equalsIgnoreCase(saB[j])){         
     System.out.println("Identical names are found and they are at position "+ i + " from the 1st array and " + j + " from the 2nd array");         
     flag = true;         
     break;       
     }     
    }   
   }   
  if (! flag){     
   System.out.println("Identical Name NOT FOUND ");   
   } 
  }
 }

【上篇】
【下篇】

抱歉!评论已关闭.