CORE API / CATATAN</>↗Core API29 Apr 2010
The chartAt() method of the String class returns the char value at the specified index. An index ranges from 0 to length() – 1. If we specified an index beyond of this range a StringIndexOutOfBoundsException exception will be thrown. These method use zero based index which means the first char value of the sequence is […]
REGEX / CATATAN</>↗Regex28 Apr 2010
If you want the entire string to match your regular expression pattern you can use the Matcher.matches() method. This method will return true if and only if entire input string matches with the matcher’s pattern. If the pattern only needs to match the beginning of the string you can use the Matcher.lookingAt() method. You can […]
CORE API / CATATAN</>↗Core API27 Apr 2010
Below is an example that can be used to get the extension of a file. The code below assume that the extension is the last part of the file name after the last dot symbol. For instance if you have a file named data.txt the extension will be txt, but if you have a file […]
REGEX / CATATAN</>↗Regex25 Apr 2010
The example below demonstrate the Matcher.lookingAt() method to check if a string starts with a pattern represented by the Pattern class. package org.kodejava.regex; import java.util.Locale; import java.util.Set; import java.util.TreeSet; import java.util.regex.Matcher; import java.util.regex.Pattern; public class MatcherLookingAtExample { public static void main(String[] args) { // Get the available countries Set<String> countries = new TreeSet<>(); Locale[] locales […]
CORE API / CATATAN</>↗Core API24 Apr 2010
For minimizing the storage used by an ArrayList to the number of its elements we can use the ArrayList.trimToSize() method call. In the code below we create an instance of ArrayList with the initial capacity set to 100. Later we only add five data into the list. To make the capacity of the ArrayList minimized […]
CORE API / CATATAN</>↗Core API22 Apr 2010
The code below show you how to get the process ID of a Java application. We can use the ManagementFactory.getRuntimeMXBean().getName() to get the process ID. In Windows the method return a string in the form of [PID]@[MACHINE_NAME]. Since JDK 10, we can use ManagementFactory.getRuntimeMXBean().getPid() method to get the process ID. This method returns the process […]