Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/361.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 字符串与子字符串比较_Java_Android - Fatal编程技术网

Java 字符串与子字符串比较

Java 字符串与子字符串比较,java,android,Java,Android,我用了两个字符串native=“+8801723519932”和local=“01723519932”, 如何比较两个字符串,以在变量中从本机“更改”获取+88。不使用子字符串公共a类{ native = "+8801723519932" local = "01723519932" change = ? **Compare both strings:-** if(native.equals(local)){ System.out.println("Match"); }else{

我用了两个字符串native=“
+8801723519932
”和local=“
01723519932
”, 如何比较两个
字符串
,以在
变量
中从本机“更改”获取
+88
。不使用
子字符串

公共a类{
native = "+8801723519932"
local = "01723519932"
change = ?

**Compare both strings:-** 

if(native.equals(local)){
   System.out.println("Match");
}else{
   System.out.println("Not Match");
}

**Get +88 from given string without using subString.**

if(native.indexOf("+88")>=0){
   System.out.println("+88");
}
公共静态void main(字符串[]args){ //TODO自动生成的方法存根 字符串nativea=“+8801723519932”; 字符串local=“01723519932”; 字符串str[]=nativea.split(本地); 对于(int i=0;i
为什么“不使用子字符串”
indexOf
substring
组合可能是最简单的方法。这是您需要的吗?可能是重复的谢谢,我已经完成了。
public class a {

public static void main(String[] args) {
    // TODO Auto-generated method stub
    String nativea="+8801723519932";
    String local = "01723519932";

    String str[]=nativea.split(local);
    for (int i = 0; i < str.length; i++) {
        String string = str[i];
        System.out.println(string);
    }
      }

   }