java两个字符串找出相同字符_用java找出两个字符串中的相同的字符??

  • Post author:
  • Post category:java


importjava.util.*;publicclassTest{publicstaticvoidmain(String[]args){test();}privatestaticvoidtest(){Stringstr1=”welcometoZhuhai”;Stringstr2=”comehere”;List<String>list=newArrayList<String>();for(inti=0;i<str1.trim().length();i++){if(str1.charAt(i)==32)continue;for(intj=0;j<str2.trim().length();j++){if(str1.charAt(i)==str2.charAt(j)&&!isExist(list,str1.substring(i,i+1)))list.add(str1.substring(i,i+1));}}display(list);}privatestaticbooleanisExist(List<String>list,Stringdest){for(Strings:list){if(dest.equals(s))returntrue;}returnfalse;}privatestaticvoiddisplay(List<String>list){for(Strings:list){System.out.println(s);}}}

阅读全文 >



版权声明:本文为weixin_31560545原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。