Java String lastIndexOf()
Java String.lastIndexOf() returns the last index of the specified character or substring in this string, if the substring is not found then it returns -1.
“Core Java” is Sun’s term, used to refer to Java SE, the standard edition and a set of related technologies, like the Java VM, CORBA, etc. This is mostly to differentiate from others like Java ME or Java EE. “Core Java” is Oracle’s definition and refers to subset of Java SE technologies.
The Core Java technologies and application programming interfaces (APIs) are the foundation of the Java Platform, Standard Edition (Java SE). They are used in all classes of Java programming, from desktop applications to Java EE applications.
Java String.lastIndexOf() returns the last index of the specified character or substring in this string, if the substring is not found then it returns -1.
Learn to find the location of a character or substring in a given string and at what index position using the String.indexOf() with examples.
Java String hashCode() returns the hashcode for the String. The hash value is used in hashing-based collections like HashMap, HashTable etc.
Java String.endsWith() verifies if the given string ends with a specified substring or not. It does not accept NULL and regex patterns.
Learn to use the String.startsWith() and StringUtils class for checking a String prefix against a single value or multiple values.
Java String compareToIgnoreCase() example compares two strings lexicographically ignoring case. Learn how it differs from equalsIgnoreCase().
Java String compareTo() method example. Learn to compare two strings lexicographically. We can consider this string comparison dictionary based comparison.
Java String.equalsIgnoreCase() compares the current string with the specified string in a case-insensitive manner. Learn with examples.
Learn to compare the content of two String objects in a case-sensitive manner using the String.equals() API. For case-insensitive comparison, we can use the equalsIgnoreCase() method. Never use ‘==’ operator for checking the strings equality. It verifies the object references, not the content, which is undesirable in most cases. 1. String.equals() API …
Java String.charAt() returns the character at specified index argument in the string object or literal. The argument must be a valid index.
This article presents a simple Java program to find duplicate characters in a String. You can modify the code to find non-repeated characters in string.
Java hashCode() and equals() methods. Learn contract between hashCode and equals methods. How to correctly override both methods and best practices.
Learn to convert float value to String using Float.toString() and String.valueOf() methods and format float to n decimal points.
Java program to convert error stack trace to String. StackTrace to String conversion may be useful when you want to print stack trace in custom logs in files or store logs in database.
You may get InvalidKeyException: Parameters missing error while performing AES encryption or decryption for password or any senstive information.
Java supports many secure encryption algorithms but some of them are too weak to be used in security-intensive applications. For example, the Data Encryption Standard (DES) encryption algorithm is considered highly insecure; messages encrypted using DES have been decrypted by brute force within a single day by machines such as …
Java examples to right pad a string with spaces or zeros to make it fixed length using the StringUtils, Strings classes and custom solution.
Java examples to left pad a string with spaces, zeros or any other pad character using the StringUtils, Strings classes and custom solution.
Java 8 StringJoiner joins strings with delimiter, prefix and suffix. Learn its usage with examples and differences with StringBuilder.
Learn to remove extra white spaces between words in a String in Java. Do not forget to check if string has leading or trailing spaces. Trim such Strings.
Learn how to trim leading and/or trailing whitespaces from a Java String using regular expressions and a new String.strip() API in Java 11.
Learn to reverse all the characters of a Java string using the recursion and StringBuilder.reverse() methods.
Learn to reverse each word in a sentence in Java with example. We will reverse words in string using StringBuilder and StringUtils classes.
Learn to check if an array contains an element. Also, learn to find the element’s index in the array. 1. Using Arrays Class To check if an element is in an array, we can use Arrays class to convert the array to ArrayList and use the contains() method to check …
Java example to convert long to String in two different ways using String.valueOf(long l) and Long.toString(long l) methods. Both are static methods.
Java examples of converting a String to a long type using Long.parseLong(String), Long.valueOf(String) and new Long(String) constructor.
In Java, converting an int value to String is not difficult, but knowing which method may save us a few CPU cycles is worth knowing.
Learn about Java wrapper classes, their usage, conversion between primitives and objects; and autoboxing and unboxing with examples. 1. Java Wrapper Classes In Java, we have 8 primitive data types. Java provides type wrappers, which are classes that encapsulate a primitive type within an Object. A wrapper class wraps (encloses) …
Learn to convert a String to title case using the WordUtils class and create a custom solution by splitting and capitalizing each word.
Java examples to do SQL-style group by sort on list of objects. It involves using multiple comparators, each of which is capable of sorting on different field in model object. Table of Contents 1. Model class and multiple comparators 2. Comparator.thenComparing() 3. CompareToBuilder 4. ComparisonChain 5. Chained comparators 1. Model …
Java xpath check if node exists or check if attribute exists in Java with example by execute an xpath expression to count the matching nodes.
This Java tutorial demonstrates how to get matching nodes for an attribute value in an XML document using XPath. 1. XPath Expressions 1.1. Input XML File First look at the XML file which we will read and then fetch information from it, using xpath queries. 1.2. XPath Expressions Now see …
Java examples to read an XML file and print XML string to console or write XML to file using StringWriter and FileOutputStream objects.
In this Java example, learn to convert XML string to XML Document and also convert XML file content to XML Document with examples.
Java examples unescapes an HTML string to a string containing the actual Unicode characters using StringEscapeUtils and a custom method.
Java examples to escape HTML using the StringEscapeUtils.escapeHtml4(), Spring’s HtmlUtils.htmlEscape() and custom logic for special cases.
Java example to create properties file from a given XML file. This code can be used to read properties key-values from XML file.
Java example to create XML file from Properties object or any existing .properties file. To convert an XML file to .properties file, follow the steps given in linked tutorial. 1. Create XML File from Properties File To convert the properties file into an XML file, the best way is to …
Learn to parse and read XML files using Java StAX parser. StAX (Streaming API for XML) provides two ways to parse XML: Cursor-based and Iterator-based APIs.
Learn to create clone of array in Java. The clone() default creates a shallow copy of an array. Use SerializationUtils.clone() for deep copy.
Learn to sort a string alphabetically using Stream.sort(), Arrays.sort() and custom sort() method using simple arrays and swapping example.
Java 8 example of sorting a collection of objects on multiple fields (ORDER BY sort) using Comparator thenComparing() method.
Learn to use Collections.sort() method to sort a list of objects using some examples. By default, the sort() method sorts a given list into ascending order (or natural order). We can use Collections.reverseOrder() method, which returns a Comparator, for reverse sorting. 1. Sorting in Natural Order and Reverse Order 1.1. …
Learn to sort a Java array of primitives, strings and custom objects in multiple ways with the help of Comparable and Comparator interfaces, Arrays.sort() and Stream.sorted() APIs. We will learn to sort arrays in natural ordering, reverse ordering and any other custom ordering as well. 1. Basics of Array Sorting …
Java examples to convert a string into string array using String.split() and java.util.regex.Pattern.slipt() methods.
Java example to create subarray from array. Learn to use Java 8 Arrays.copyOfRange() method along with converting the subarray to list object.
Java examples to use DateTimeFormatter for formatting ZonedDateTime, LocalDateTime, LocalDate and LocalTime with inbuilt and custom patterns.
Java 8 examples to convert from LocalDate to java.sql.Date and vice versa.
Java examples to convert from LocalTime to java.sql.Time and vice versa.
Learn to convert from java.time.LocalDate to java.util.Date and vice-versa using the easy-to-understand Java examples. 1. Convert Date to LocalDate The Date.getTime() method returns the epoch milliseconds i.e. the number of milliseconds since January 1, 1970, 00:00:00 GMT. To get the LocalDate, we need to first set the zone offset information …
HowToDoInJava provides tutorials and how-to guides on Java and related technologies.
It also shares the best practices, algorithms & solutions and frequently asked interview questions.