diff --git a/LinearSearchString.java b/LinearSearchString.java new file mode 100644 index 0000000..4d715f5 --- /dev/null +++ b/LinearSearchString.java @@ -0,0 +1,38 @@ + +import java.util.Arrays; + +public class LinearSearchSrting { + public static void main(String[] args) { + String name = "Lokesh"; + char target = 'L'; + System.out.println(linearSearch(name, target)); + System.out.println(linearSearch2(name, target)); + System.out.println("String as Char array: " + Arrays.toString(name.toCharArray())); + // if Arrays.toString is not used, output will be address of an array : [C@2d98a335 + } + static boolean linearSearch(String str , char target){ // we can change the name of target. + if(str.length() == 0){ + return false; + } // return false if the string is empty. + + for (int i =0; i