Friday 19 October 2018

Strings in Java (Part 2)




Hey Friendz.

In this post, we are going to discuss string-specific methods. these methods are very useful, at the time of programming.

There are more than 40 methods in Java 1.7. Here, we are going to discuss the most common methods.



char charAt(int index)

Returns the character at the specified index.

String concat(String str)

Concatenates the specified string to the end of this string.

boolean endsWith(String suffix)

Tests if this string ends with the specified suffix.

int length()

Returns the length of this string.

boolean matches(String regex)

Tells whether or not this string matches the given regular expression.

String replace(char oldChar, char newChar)

Returns a new string resulting from replacing all occurrences of oldChar in this string with newChar.

String replaceAll(String regex, String replacement)

Replaces each substring of this string that matches the given regular expression with the given replacement.

String[] split(String regex)

Splits this string around matches of the given regular expression.

boolean startsWith(String prefix)

Tests if this string starts with the specified prefix.

char[] toCharArray()

Converts this string to a new character array.

String substring(int beginIndex, int endIndex)

Returns a new string that is a substring of this string.

String substring(int beginIndex)

Returns a new string that is a substring of this string.

String toLowerCase()

Converts all of the characters in this String to lower case using the rules of the default locale

String toUpperCase()

Converts all of the characters in this String to upper case using the rules of the default locale.

String trim()

Returns a copy of the string, with leading and trailing whitespace omitted.


♣♣  Compaire two Strings

  1. Based On Memory Location [ == ]
  2. Based On String sequence [ .equals() ]
  3. Based On Lexicographical order [ compaireTo ]

refer this website  -- www.baeldung.com






Here are the links and videos... You can find good programs here and please understand all logical concept from here and practice all logical programs...to become a good java developer.

beginnersbook -- Go Here

Java CodeExample -- Go Here (one more good site) 




# Videos 




String Part 1




String Part 2





1 comment: