【equalsIgnoreCase】的作用

用来比较两个字符串的是否相等,不区分大小写,例如:

String myStr1 = "Hello";
String myStr2 = "HELLO";
String myStr3 = "Another String";
System.out.println(myStr1.equalsIgnoreCase(myStr2)); // true
System.out.println(myStr1.equalsIgnoreCase(myStr3)); // false

例题:

字符串比较

题目描述
给定两个仅由大写字母或小写字母组成的字符串(长度介于1到10之间),它们之间的关系是以下4中情况之一:
1:两个字符串长度不等。比如 Beijing 和 Hebei
2:两个字符串不仅长度相等,而且相应位置上的字符完全一致(区分大小写),比如 Beijing 和 Beijing
3:两个字符串长度相等,相应位置上的字符仅在不区分大小写的前提下才能达到完全一致(也就是说,它并不满足情况2)。比如 beijing 和 BEIjing
4:两个字符串长度相等,但是即使是不区分大小写也不能使这两个字符串一致。比如 Beijing 和 Nanjing
编程判断输入的两个字符串之间的关系属于这四类中的哪一类,给出所属的类的编号。
输入
包括两行,每行都是一个字符串
输出
仅有一个数字,表明这两个字符串的关系编号
样例输入
BEIjing
beiJing
样例输出
3

code:

import java.util.Scanner;
 
public class Main {
 
    static String a;
 
    static String b;
 
 
    static int check(){
        if(a.length() !=b.length()){
            return 1;
        } else {
            if(a.equals(b)){
                return 2;
            } else {
                if (!a.equalsIgnoreCase(b))return 4;
            }
        }
        return 3;
    }
 
    public static void main(String[] args) {
        Scanner sc= new Scanner(System.in);
        a = sc.nextLine().trim();
        b =sc.nextLine().trim();
        int res =check();
        System.out.println(res);
    }
}
 
/**************************************************************
    Problem: 2385
    User: 202001020125
    Language: Java
    Result: 正确
    Time:1019 ms
    Memory:18768 kb
****************************************************************/
  • 3
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论
这是一款简单的rss阅读器,用xml解析 package com.fenghuo.xml; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.UnsupportedEncodingException; import java.util.ArrayList; import java.util.List; import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; import org.apache.http.entity.InputStreamEntity; import org.xml.sax.Attributes; import org.xml.sax.InputSource; import org.xml.sax.SAXException; import org.xml.sax.helpers.DefaultHandler; import com.fenghuo.model.RssItem; public class ParseRssSAX { public static List<RssItem> parseRss(InputStream is, String encode) { try { SAXParser parser = SAXParserFactory.newInstance().newSAXParser(); InputSource in = new InputSource(new InputStreamReader(is, encode)) ; RssParserHandler handler = new RssParserHandler(); parser.parse(in, handler) ; return handler.getData(); } catch (ParserConfigurationException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (SAXException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; } } class RssParserHandler extends DefaultHandler{ private List<RssItem>data; public RssParserHandler(){ this.data=new ArrayList<RssItem>(); title=link=pubDate=description=""; } public List<RssItem>getData(){ return data; } private String title,link,pubDate,description; private boolean isTitle = false , isLink = false , isPubDate = false , isDest = false; @Override public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { // TODO Auto-generated method stub if(localName.equalsIgnoreCase("title")){ isTitle=true; } else if(localName.equalsIgnoreCase("link")) { isLink = true; } else if(localName.equalsIgnoreCase("pubDate")) { isPubDate = true; } else if(localName.equalsIgnoreCase("description")) { isDest = true; } else if(localName.equalsIgnoreCase("item")) { title = link = pubDate = description = ""; } } @Override public void endElement(String uri, String localName, String qName) throws SAXException { // TODO Auto-generated method stub if(localName.equalsIgnoreCase("title")) { isTitle = false; } else if(localName.equalsIgnoreCase("link")) { isLink = false; } else if(localName.equalsIgnoreCase("pubDate")) { isPubDate = false; } else if(localName.equalsIgnoreCase("description")) { isDest = false; } else if(localName.equalsIgnoreCase("item")) { RssItem item = new RssItem(title, link, pubDate, description); // Log.e("sax,item" , item.toString()); data.add(item); } } @Override public void characters(char[] ch, int start, int length) throws SAXException { // TODO Auto-generated method stub String text=new String(ch,start,length); text=text.trim(); if(isTitle){ title+=text; }else if(isLink){ link+=text; }else if(isDest){ description+=text; }else if(isPubDate){ pubDate+=text; } } }

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

是君倩

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值