Object Oriented Programming Articles

Page 200 of 589

Function pointers in Java

Akshaya Akki
Akshaya Akki
Updated on 11-Mar-2026 2K+ Views

From Java 8 onwards, the lambda expression is introduced which acts as function pointers.Lambda expressions are introduced in Java 8 and are touted to be the biggest feature of Java 8. Lambda expression facilitates functional programming and simplifies the development a lot.SyntaxA lambda expression is characterized by the following syntax.parameter -> expression bodyFollowing are the important characteristics of a lambda expression.Optional type declaration − No need to declare the type of a parameter. The compiler can inference the same from the value of the parameter.Optional parenthesis around parameter − No need to declare a single parameter in parenthesis. For multiple ...

Read More

Search and Replace with Java regular expressions

Sravani S
Sravani S
Updated on 11-Mar-2026 1K+ Views

Java provides the java.util.regex package for pattern matching with regular expressions. Java regular expressions are very similar to the Perl programming language and very easy to learn.A regular expression is a special sequence of characters that help you match or find other strings or sets of strings, using a specialized syntax held in a pattern. They can be used to search, edit, or manipulate text and data.The replaceFirst() and replaceAll() methods replace the text that matches a given regular expression. As their names indicate, replaceFirst replaces the first occurrence, and replaceAll replaces all occurrences.Exampleimport java.util.regex.Matcher; import java.util.regex.Pattern; public class RegexMatches {   ...

Read More

How to split a Java String into tokens with StringTokenizer?

Abhinanda Shri
Abhinanda Shri
Updated on 11-Mar-2026 542 Views

The hasMoreTokens() method is used to test if there are more tokens available from this tokenizer's string.Exampleimport java.util.*; public class StringTokenizerDemo {    public static void main(String[] args) {       // creating string tokenizer       StringTokenizer st = new StringTokenizer("Come to learn");       // checking elements       while (st.hasMoreElements()) {          System.out.println("Next element : " + st.nextElement());       }    } }OutputNext element : Come Next element : to Next element : learn

Read More

How to check if a String contains another String in a case insensitive manner in Java?

Alankritha Ammu
Alankritha Ammu
Updated on 11-Mar-2026 2K+ Views

One way to do it to convert both strings to lower or upper case using toLowerCase() or toUpperCase() methods and test.Examplepublic class Sample {    public static void main(String args[]){       String str = "Hello how are you welcome to Tutorialspoint";       String test = "tutorialspoint";       Boolean bool = str.toLowerCase().contains(test.toLowerCase());       System.out.println(bool);    } }Outputtrue

Read More

Write a java program to tOGGLE each word in string?

Alankritha Ammu
Alankritha Ammu
Updated on 11-Mar-2026 1K+ Views

You can change the cases of the letters of a word using toUpperCase() and toLowerCase() methods.Split each word in the string using the split() method, change the first letter of each word to lower case and remaining letters to upper case.Examplepublic class Sample{    public static void main(String args[]){       String sample = "Hello How are you";       String[] words = sample.split(" ");       String result = "";       for(String word:words){          String firstSub = word.substring(0, 1);          String secondSub = word.substring(1);          result = result+firstSub.toLowerCase()+secondSub.toUpperCase()+" ";       }       System.out.println(result);    } }OutputhELLO hOW aRE yOU

Read More

StringTokenizer class in Java

V Jyothi
V Jyothi
Updated on 11-Mar-2026 685 Views

The StringTokenizer class of the java.util package allows an application to break a string into tokens.This class is a legacy class that is retained for compatibility reasons although its use is discouraged in new code.Its methods do not distinguish among identifiers, numbers, and quoted strings.This class methods do not even recognize and skip comments.Exampleimport java.util.*;   public class Sample {    public static void main(String[] args) {         // creating string tokenizer       StringTokenizer st = new StringTokenizer("Come to learn");         // checking next token       System.out.println("Next token is : " + st.nextToken());   }     }OutputNext token is : Come

Read More

Java String toCharArray() method example.

Sai Nath
Sai Nath
Updated on 11-Mar-2026 148 Views

The toCharArray() method of a String class converts this string to a character array.Exampleimport java.lang.*; public class StringDemo {    public static void main(String[] args) {       // converts String value to character array type value       String str = " Java was developed by James Gosling";       char retval[] = str.toCharArray();       // displays the converted value       System.out.println("Converted value to character array = ");       System.out.println(retval);    } }OutputConverted value to character array = Java was developed by James Gosling

Read More

How to test String is null or empty?

V Jyothi
V Jyothi
Updated on 11-Mar-2026 616 Views

We can verify whether the given string is empty using the isEmpty() method of the String class. This method returns true only if length() is 0.Exampleimport java.lang.*; public class StringDemo {    public static void main(String[] args) {       String str = "tutorialspoint";       // prints length of string       System.out.println("length of string = " + str.length());       // checks if the string is empty or not       System.out.println("is this string empty? = " + str.isEmpty());    } }Outputlength of string = 14 is this string empty? = false

Read More

How to Split a String with Escaped Delimiters?

Sravani S
Sravani S
Updated on 11-Mar-2026 515 Views

The split(String regex) method of the String class splits this string around matches of the given regular expression.Examplepublic class Sample{    public static void main(String args[]){       String s = "|A|BB||CCC|||";       String[] words = s.split("\|");       for (String string : words) {          System.out.println(string);       }    } }OutputA BB CCC

Read More

Java string case change sample code examples.

Abhinanda Shri
Abhinanda Shri
Updated on 11-Mar-2026 201 Views

You can change the cases using the toUpperCase() and toLowerCase() methods of the String class.Examplepublic class Sample {    public static void main(String args[]){       String str = "Hello how are you";       String strUpper = str.toUpperCase();       System.out.println("Lower to upper : "+strUpper);       String strLower = str.toLowerCase();       System.out.println("Upper to lower : "+strLower);    } }OutputLower to upper : HELLO HOW ARE YOU Upper to lower : hello how are you

Read More
Showing 1991–2000 of 5,881 articles
« Prev 1 198 199 200 201 202 589 Next »
Advertisements