190 likes | 405 Views
**** Java Certification Training: https://www.edureka.co/java-j2ee-soa-training ****<br>This Edureka tutorial on u201cJava Stringsu201d will talk about one of the most important classes of Java i.e String class. It will also talk about the various methods and interfaces implemented by the String class. Through this tutorial you will learn the following topics:<br>Java Strings<br>String Pool<br>Creating a String<br>String Methods<br><br>Check out our Java Tutorial blog series: https://goo.gl/osrGrS<br><br>Check out our complete Youtube playlist here: https://goo.gl/gMFLx3<br><br>Follow us to never miss an update in the future.<br>YouTube: https://www.youtube.com/user/edurekaIN<br>Instagram: https://www.instagram.com/edureka_learning/<br>Facebook: https://www.facebook.com/edurekaIN/<br>Twitter: https://twitter.com/edurekain<br>LinkedIn: https://www.linkedin.com/company/edureka
E N D
Hands On Java String Creating a String String Pool String Methods
Java String Object 01 String is a Java object Characters 02 Represents a sequence of characters Class 03 java.lang.String class is used to create and manipulate strings Immutable 04 A string is immutable in nature JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
Java Strings With Strings in Java you can perform various operations, some of which are: Search The quick brown fox jumps over the lazy dog Create Substring The quick brown fox jumps over the lazy dog The quick brown fox jumps over the lazy dog The quick fox jumps The quick brown fox jumps over the lazy dog Create new strings The quick lazy dog JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
Java Strings java.lang.String JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
Java Strings Serializable Comparable CharSequence java.lang.String public final class String extends Object implements Serializable, Comparable<String>, CharSequence JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
Java Strings Serializable is a marker interface that contains no data member or method. It is used to “mark” the java classes so that objects of these classes may get a specific capability Serializable Comparable interface is used for ordering the objects of any user-defined class. This interface is found in java.lang.package and contains only one method named compareTo(Object) Comparable A CharSequence interface is a readable sequence of characters. This interface provides uniform, read-only access to various kind of character sequences CharSequence JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
Java Strings CharSequence String StringBuffer StringBuilder java.lang.StringBuilder is identical to StringBuffer except for one important difference that it is not synchronized, which means it is not thread safe java.lang.String class is used to create string objects and provides a list of methods to create and manipulate Strings java,lang.StringBuffer is a peer class of String that represents growable and writable character sequences JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
String Pool Heap Memory Java String pool refers to collection of Strings which are stored in heap memory String Pool As String objects are immutable in nature the concept of String Pool came into the picture String Pool helps in saving space for Java Runtime JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
Keyword Literal new Creating a String
Creating a String – Using Literal Java String literal is created by using double quotes String str = “Edureka”; Keyword Before creating a String literal first looks for String with same value in the String pool, if found it returns the reference else it creates a new String in the pool & returns the reference Literal new Heap Memory str String Pool Edureka String str1 = “Edureka”; str1 Welcome str2 String str2 = “Welcome”; JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
Creating a String – Using new Keyword String object created using “new” keyword it always create a new object in heap memory String str = new String (“Edureka”); Keyword Literal new Heap Memory str String Pool str1 Edureka str2 Welcome str3 Edureka JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
String Methods Checks the equality of string with the given object boolean equals(Object another) Compares another string without matching the case equalsIgnoreCase() Returns a strings length length() Returns a character at a index ‘i’ charAt(i) Returns the string in uppercase toUpperCase() Returns the string in lowercase toLowerCase() Replaces all occurrences of the specified char value with the given value replace(oldVal, newVal) Removes the white spaces from the beginning and ending of string trim() Checks for the matching sequence of char value and returns true/false contains("value") Converts a string to a new character array toCharArray() Checks whether the string is empty or not IsEmpty() Checks if the string ends with the specified suffix endsWith() Concatenates two strings concat() JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training