Java Strings Tutorials
All Java String Examples Tutorial
Favourite tutorials for developers
In Java, we use StringTokenizer to split a string into multiple tokens. The StringTokenizer is a legacy class, try the split method of String.
In Java, we can use ByteArrayInputStream to convert a String to an InputStream. We will examine how to use ByteArrayInputStream to convert a String to an InputStream and saves it into a file.
This article shows a few ways to convert an java.io.InputStream to a String. We will examine a few ways: using ByteArrayOutputStream, using InputStream#readAllBytes (Java 9), using InputStreamReader + StringBuilder, InputStreamReader + BufferedReader, using Java 8 BufferedReader#lines, using Apache Commons IO.
In Java, we can use Integer.parseInt(String) to convert a String to an int; For unparsable String, it throws NumberFormatException. We will examine deeply on how to convert String to primitive type int and how to handle NumberFormatException.
In Java, we can use Integer.valueOf(String) to convert a String to an Integer object; For unparsable String, it throws NumberFormatException. We will examine deeply on how to convert a String to an object Integer and how to handle NumberFormatException.
Few Java examples to show you how to check if a String is numeric. We have several ways to check numeric string: using Character.isDigit(), using NumberUtils.isDigits() from Apache Commons Lang
In Java, we can use String#split() to split a string. We will examine deeply many ways or options to split a string.
In Java, we use equals() to compare string value. In this article, we will show you a few ways to compare strings in Java: using equals(), using equalsIgnoreCase(), using contentEquals(), using compareTo(), using Objects.equals() and String interning.
The Java String compareTo() method compares two strings lexicographically (alphabetical order). It returns a positive number, negative number, or zero. if s1 < s2, it …