CORE API / CATATAN</>↗Core API14 Mar 2006
Here is a code example for creating text file and put some texts in it. This program will create a file called write.txt. To create and write a text file we do the following steps: File file = new File("write.txt"); FileWriter fileWriter = new FileWriter(file); BufferedWriter bufferedWriter = new BufferedWriter(fileWriter); Below is the complete code […]
CORE API / CATATAN</>↗Core API13 Mar 2006
The code snippet below is an example of how to read a text file using BufferedReader class from the java.io package. This snippet read a text file called README.md and print out its content. To create an instance of java.io.BufferedReader we do the following steps: File file = new File("README.md"); FileReader fileReader = new FileReader(file)); […]
CORE API / CATATAN</>↗Core API08 Mar 2006
When we have an application that used a text file to store a configuration, and the configuration is typically in a key=value format then we can use java.util.Properties to read that configuration file. Here is an example of a configuration file called app.config: app.name=Properties Sample Code app.version=1.0 The code below show you how to read […]
CORE API / CATATAN</>↗Core API06 Mar 2006
To convert collection-based object into an array we can use toArray() or toArray(T[] a) method provided by the implementation of Collection interface such as java.util.ArrayList. package org.kodejava.util; import java.util.List; import java.util.ArrayList; public class CollectionToArrayExample { public static void main(String[] args) { List<String> words = new ArrayList<>(); words.add("Kode"); words.add("Java"); words.add("-"); words.add("Learn"); words.add("Java"); words.add...
CORE API / CATATAN</>↗Core API02 Mar 2006
To convert array based data into List / Collection based we can use java.util.Arrays class. This class provides a static method asList(T… a) that converts array into List / Collection. package org.kodejava.util; import java.util.Arrays; import java.util.List; public class ArrayAsListExample { public static void main(String[] args) { String[] words = {"Happy", "New", "Year", "2021"}; List<String> list […]
CORE API / CATATAN</>↗Core API28 Feb 2006
The java.util.Calendar allows us to do a date arithmetic function such as add or subtract a unit of time to the specified date field. The method that done this process is the Calendar.add(int field, int amount). Where the value of the field can be Calendar.DATE, Calendar.MONTH, Calendar.YEAR. So this mean if you want to subtract […]