12:23 am - Monday May 1, 2017

Archive: Java Examples Subscribe to Java Examples

HashMap example programs and Tutorial in java

BACK   1.Creating  a clone(duplicate) of HashMap using Object clone   2.Remove a value from HashMap by its key using  remove(Object key )   3.Check whether the HashMap is empty boolean isEmpty( )   4.Change the HashMap to Collection (value)...

check suffix of the string boolean endswith(string suffix)

                    This method returns true if the character sequence represented by the argument is a suffix of the character sequence represented by this object,false otherwise.                     Note...

Check whether the given char sequence is found in the string boolean contains(CharSequence s)

                               This method returns true while comparing two string value. And if this string contains the specified sequence of char value. Example Program public class Model1 { public static...

Concatenate two string String concat(String str)

                                      Concatenation method is used for joining two string. Example Program public class Model1 { public static void main(String args[]) { String k...

compare two string in dictionary order (without case) int compareToIgnoreCase(string str)

                             The method will compare two string lexicographically(compiling a dictionary), but it will ignores in case of differences. Example Program public class Model1 { public static void...

Compare two string in dictionary order int compareTo(String anotherStr)

                                 Compares two strings lexicographically(compiling a dictionary order) Example Program public class Model1 { public static void main(String args[]) { String s1...

Retrieve the character at given position char charAt( int index)

                                                  This method returns the character value at the specified index.The string indexes value is start from zero. Example Program public class...

Replace all String matches the given regex String replaceAll(String regex, String replacement)

                                              This method is used to replace the character using regular expression(i.e., old character will be specified with regular expression). Depends upon the...

Replace a character with new character String replace(char oldChar,char newChar)

                               This method is used to replace the specified character in the given string. Old character will be replaced by a new character. If the specified character occured number of times in...

Check whether a given regex matches in a string boolean matches(String regex)

                                                        This method is used to check whether the string match with the regular expression format.If it match with regular expressions it returns...

Find the length of the string int length()

                                           This method is used to return the length of the string. Example Program public class Len { public static void main(String args[]) { ...

Search index of a character from given position lastIndexOf(int ch,int fromIndex)

                                              This method returns the occurrence of the specified character within a specified range.If the specified character placed as many times within the specified range means then...

Search index of a character from given position lastIndexOf(int ch,int fromIndex)

                                                                                           This method  returns the occurrence of the specified character...

Check whether a given string is empty boolean isEmpty()

                                This method return true or false value. If the string variable contains any string value it return false,Otherwise it return true(If the input is empty). To return true or false...

String object in String pool String intern( )

                                 This method returns the canonical representation for the string object. Intern string have an entry in the global string pool. Initially the pool is empty and the and the strings...

Retrieves the index position of given string int indexOf(String str)

               This method display the index value for the specified substring in a given string. Example Program public class Index2 { public static void main(String[] args) { String s1="Java developed...

Retrieve index position of a char from specified index int indexOf(int ch, int fromIndex)

                         This method returns the index value for the specified character in a given string. It is used for the first occurrence of the specified character.If the string value has some same character in...

Retrieve index position of given character int indexOf(int ch)

                               This method returns the index value for the specified character in a given string. It is used for the first occurrence of the specified character. If the string value has some same...

Get HashCode of a given string int hashcode( )

This method returns a hash code for the given input. Example Program public class Hash { public static void main(String[] args) { String s= “Srilekha"; Integer i=15; Float f=12.0f; System.out.println("String...

Encode given string to byte array byte[ ] getBytes[ ]

                   This function encodes the given string into a sequence of bytes using default character set and stores the new byte value in another byte array. Example Program public class Byte1 { public static void...