Java Tutorial for Beginners 2023 | String Methods in Java | Java String Class | Parnika Tutorials

Pubblicato il: 30 gennaio 2022
sul canale di: Parnika Tutorials
630
12

"Java Tutorial for Beginners 2023 | String Methods in Java | Java String Class | Parnika Tutorials
#stringclass #stringmethod #javastrings #javaclasses #featuresjava #java #javafullcourse #javatutorials #javaforbeginners #javalanguage #learnjava #javacompletecourse #javaprogramming #javatutorialforbeginners #parnikatutorials #javacourse #java2023 #javacourse2023
00:00 - Introduction
00:39 - What is a String
01:28 - How to declare a string
05:39- String methods
46:40 - Implementation of string methods
previous video - #16 COMMAND LINE ARGUMENTS IN JAVA | JAVA COURSE FOR BEGINNERS | JAVA PROGRAMMING

   • Command Line Argument in Java | Java Progr...  "
Social media Links:
Instagram:   / parnikatutorials  
Website:
Email id: parnikatutorials@gmail.com
To get the regular updates:
Telegram link: https://t.me/Parnikatutorials
Facebook: https://m.facebook.com/profile.php?id...
Linkedin:   / parnika-tutorials-a8a9831b2  
Pinterest:   / parnikatutorials0892  


String is a sequence of characters. In java, objects of String are immutable which means a constant and cannot be changed once created.

Creating a String

There are two ways to create string in Java:

String literal

String s = “GeeksforGeeks”;

Using new keyword

String s = new String (“GeeksforGeeks”);
String Methods

int length(): Returns the number of characters in the String.

"GeeksforGeeks".length(); // returns 13

Char charAt(int i): Returns the character at ith index.

"GeeksforGeeks".charAt(3); // returns ‘k’

String substring (int i): Return the substring from the ith index character to end.

"GeeksforGeeks".substring(3); // returns “ksforGeeks”

String substring (int i, int j): Returns the substring from i to j-1 index.

"GeeksforGeeks".substring(2, 5); // returns “eks”

String concat( String str): Concatenates specified string to the end of this string.

String s1 = ”Geeks”;
String s2 = ”forGeeks”;
String output = s1.concat(s2); // returns “GeeksforGeeks”

int indexOf (String s): Returns the index within the string of the first occurrence of the specified string.

String s = ”Learn Share Learn”;
int output = s.indexOf(“Share”); // returns 6

int indexOf (String s, int i): Returns the index within the string of the first occurrence of the specified string, starting at the specified index.

String s = ”Learn Share Learn”;
int output = s.indexOf("ea",3);// returns 13

Int lastIndexOf( String s): Returns the index within the string of the last occurrence of the specified string.

String s = ”Learn Share Learn”;
int output = s.lastIndexOf("a"); // returns 14

boolean equals( Object otherObj): Compares this string to the specified object.

Boolean out = “Geeks”.equals(“Geeks”); // returns true
Boolean out = “Geeks”.equals(“geeks”); // returns false

boolean equalsIgnoreCase (String anotherString): Compares string to another string, ignoring case considerations.

Boolean out= “Geeks”.equalsIgnoreCase(“Geeks”); // returns true
Boolean out = “Geeks”.equalsIgnoreCase(“geeks”); // returns true

int compareTo( String anotherString): Compares two string lexicographically.

int out = s1.compareTo(s2); // where s1 ans s2 are
// strings to be compared

This returns difference s1-s2. If :
out -ve // s1 comes before s2
out = 0 // s1 and s2 are equal.
out +ve // s1 comes after s2.

int compareToIgnoreCase( String anotherString): Compares two string lexicographically, ignoring case considerations.

int out = s1.compareToIgnoreCase(s2);
String toLowerCase(): Converts all the characters in the String to lower case.

String word1 = “HeLLo”;
String word3 = word1.toLowerCase(); // returns “hello"

String toUpperCase(): Converts all the characters in the String to upper case.

String word1 = “HeLLo”;
String word2 = word1.toUpperCase(); // returns “HELLO”

String trim(): Returns the copy of the String, by removing whitespaces at both ends. It does not affect whitespaces in the middle.


In questa pagina del sito puoi guardare il video online Java Tutorial for Beginners 2023 | String Methods in Java | Java String Class | Parnika Tutorials della durata di ore minuti seconda in buona qualità , che l'utente ha caricato Parnika Tutorials 30 gennaio 2022, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 630 volte e gli è piaciuto 12 spettatori. Buona visione!