Home » Core Java » lang » String (page 2)

String

Java String matches Example

In this example we are going to talk about matches String Class method. You can use this method to test a String against a regular expression. Testing a String against a regular expression is a very common operation for interactive applications, as it is heavily used to perform validity checks on user input. It can also be used for several ...

Read More »

Java String length Example

In this example we are going to see how you can find out the length of the a String in Java. By length we mean that number of Unicode characters or Code Units. String class has a very convenient method of doing so: length(). Here is how you can use it :           StringFromatExample.java: package com.javacodegeeks.core.string; ...

Read More »

Java String format Example

Last updated Jan. 14, 2019 In this post, we feature a comprehensive Java String format Example. We are going to see how to format Strings in Java. Developers familiar with C, will find the methods used here resembling printf function. And the formatting specifications are very similar. In fact, PrintStream class in Java, has a member function called printf designed ...

Read More »

Java String Contains Example

In this example we are going to see how you can check if a String contains another String in Java. The Java String Class API offers a method to do that, contains. To be more specific the complete signature of contains method is public boolean contains(CharSequence s). Which means that you are trying to see, whether a CharSequence s resides ...

Read More »

Java String Concatenation Example

In this example we are going to see how you can concatenate two Strings, or in fact, any Object with a String. As we’ve mention in an introductory article about Java String Class, String is one of the most used types in Java programs. So Java creators wanted to make the usage of Strings as straightforward as possible. Admittedly, concatenation ...

Read More »

Java String CompareTo Example

In a previous post, Java String Compare Example, we showed how to compare two Strings in java. In that example the test was simple : check if two String objects are equal. But consider the case when you have a collection of Strings and you want to sort it. Of course, equality check is not enough. You have to impose ...

Read More »

Java String Compare Example

Today we are going to focus on how you can compare Strings in Java. By comparing, in this case, we mean to check if their values are equal. In the previous example we talked generally about the Java String Class. We stated that Java let’s you initialize a String like a primitive, and use the ‘+’ operator like you would ...

Read More »

Java String Class Example

1. Introduction In this example we are going to discuss about the basic characteristics of Java String Class. String is probably one of the most used types in Java programs. That’s why Java provides a number of API methods that make String manipulation easy and efficient, straight out of the box. Strings are so important that even in the latest ...

Read More »

How to convert String to InputStream in Java

In the previous tutorial, we discussed how can we convert an InputStream into a String. In this tutorial we are going to see the opposite direction. So, we are going to covert a String into an InputStream. When you have a very big String that you want to process it incrementally, or a small portion of it at a time, ...

Read More »

How to Convert InputStream to String in Java

In this tutorial we are going to show three different methods that you can use in order to read a file and convert it to String in Java. The way to read a file with Java is pretty straightforward, you use an FileInputStream. But sometimes you might want to perform several operations in that Stream, for example you might want ...

Read More »