Home » Core Java » lang » String

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 »

String length Java Example

In this example, we are going to see how you can find out the length of a String in Java. By length string, we mean the number of Unicode characters or Code Units. 1. What is String in Computer Programming In computer programming, a string is traditionally sequence of characters, either as a literal constant or as some kind of variable. The latter may allow its elements to ...

Read More »

String.format Java Example

In this post, we feature a comprehensive String.format Java Example. In Java, printf is exactly like string.format, but it does not return anything, it only prints the result. 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 ...

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 Concatenate Strings Example

In this example, we are going to see how you can concatenate two Strings, or in fact, any Object with a String in Java. As we’ve mentioned 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. ...

Read More »

String CompareTo Java Example

In this post, we feature a comprehensive String CompareTo Java Example. In a previous post, Java Compare Strings 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 ...

Read More »

Java Compare Strings 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 lets you initialize a String like a primitive, and use the ‘+’ operator like you would ...

Read More »

Java String Class Example

This article talks about one of the widely used String library in Java which does no less than magic. It goes through some of the common Java String methods available previous to Java 8. Then it specifies some of the important String methods introduced in and after Java 8. You can also check this tutorial in the following video: Java ...

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 »