How to search an array of strings starting with a keyword?
eg,
String[] str = { "abcd", "abdc", "bcda"};
when my search bar "a", it should show
"a"
abcd and abdc
when my search bar "abc", then it should be "abcd".
"abc"
"abcd"
String[] strArray = {"abcd", "abdc", "bcda"}; for (String s : strArray) if (s.startsWith(searchTerm)) System.out.println(s);
Change startsWithfor contains, you just want to look for containment.
startsWith
contains
You should check this method:
http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html#contains%28java.lang.CharSequence%29
Source: https://habr.com/ru/post/1745445/More articles:Fast ruby http library for large XML downloads - httpjqgrid delGridRow not working - jqueryHow to set local buffer variable from Eval: to .dir-local.el? - emacsC # How to create objects without defining classes? - c #Есть ли рекомендуемый подход для обработки данных сохранения в ответ на внутрисайтовую навигацию без события onunload? - jqueryI need an efficient protocol between web services that are more or less supported by all major languages - textThe permutation algorithm in the form - algorithmAdd new language to existing localization of Xcode project - iphonedestruction of an object in a vector when adding a new object - c ++Beginner C ++ - open a text file for reading, if it exists, if not, create it empty - c ++All Articles