Checking whether a file or directory

Checking whether the File object exists if exists then check whether it is file of directory to check file existance exists() method of File class is used if it returns true means file or directory exists, at this point we are not confirm existing File object is file or directory. To check file object isDirectory() … Read more

Reading a file using FileInputStream

Reading a text file

For reading a file we have to create a FileReader object. Then we create BufferedReader object of FileReader. If file not found FileReader constructor throws FileNotFoundException. If br.readLine() is not able to read source file it throws IOException.

indexof and lastindexof

indexOf(int ch) returns int value that is the first occurrence of specified character in given string. Counting start from 0. If character not found it returns -1 indexOf(int ch, int fromIndex) returns int value that is the first occurrence of specified character in given string after specified position. If character not found it returns … Read more

Java Finding a sub string in string

indexOf(String str) return int value that is the index value of str if found in string other wise it returns -1.The index value start from 0. contains(CharSequence str) returns boolean value if str is present in given string it will return true else false.

Concatenating two strings

The + operator can be used for concatenation of strings. concat(String str) is a method of String class that concatenate two strings and return a String.

String matching and comparing

equals(Object anObject) compare String with object and returns boolean value, for comparing two strings if both are strictly equals(case sensitive) then it will return true else false value. equalsIgnoreCase(String anotherString) compare two strings with case ignorance and return boolean value. compareTo(String anotherString) compare two strings and return int value if both are equal(with case) … Read more

Converting given string to upper and lower case

toUpperCase() and toLowerCase() are methods in String class which converts given string in upper and lower case respectively and return a string.

Splitting the strings in words

Counting the number of characters and words in given string