Substring search in Java

前端 未结 6 400

I have a problem with string comparison. For example, there is this string:

\"hello world i am from heaven\"

I want to search if this strin

6条回答
  •  被撕碎了的回忆
    2021-01-18 07:19

    I got the solution finally.

    public void onTextChanged(CharSequence s, int start, int before, int count) {
    
                            ArrayList> arrayTemplist = new ArrayList>();
                            String searchString = mEditText.getText().toString();
                            if(searchString.equals("")){new DownloadJSON().execute();}
    
                        else{
    
    
                        for (int i = 0; i < arraylist.size(); i++) {
                            String currentString = arraylist.get(i).get(MainActivity.COUNTRY);
                            if (searchString.toLowerCase().contains(currentString.toLowerCase())) {
        //pass the character-sequence instead of currentstring
    
                                arrayTemplist.add(arraylist.get(i));
                            }
                        }
                            }
                            adapter = new ListViewAdapter(MainActivity.this, arrayTemplist);
                            listview.setAdapter(adapter);
    
                    }
    
    
                });
        }
    

    Replace the above code with this one:

    public void onTextChanged(CharSequence s, int start, int before, int count) {
    
                            ArrayList> arrayTemplist = new ArrayList>();
                            String searchString = mEditText.getText().toString();
                            if(searchString.equals("")){new DownloadJSON().execute();}
    
                        else{
    
    
                        for (int i = 0; i < arraylist.size(); i++) {
                            String currentString = arraylist.get(i).get(MainActivity.COUNTRY);
                            if (currentString.toLowerCase().contains(searchString.toLowerCase())) {
        //pass the character-sequence instead of currentstring
    
                                arrayTemplist.add(arraylist.get(i));
                            }
                        }
                            }
                            adapter = new ListViewAdapter(MainActivity.this, arrayTemplist);
                            listview.setAdapter(adapter);
    
                    }
    
    
                });
    

提交回复
热议问题