Tag Archives: Java

Java – Check Empty String

If you don’t want to use Apache Commons which i show you in previous post. You can use the following static function to check if a string is empty.

public static boolean notEmpty(String s) {
  return (s != null && s.length() > 0);
}

 

Done =)

Reference:

Java – JCalendar for Date Selection

Previously i have created two posts about a simple Swing Date Picker.

 

Here comes a better solution – JCalendar.

JCalendar is Java Bean which provides a complete feature of a Date Picker in Java. For more information, please visit JCalendar Java Bean, a Java Date Chooser Continue reading Java – JCalendar for Date Selection

Java – Convert String to InputStream

If you want to convert a String into InputStream, you can use the following piece of code.

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import org.apache.commons.io.IOUtils;

public class ConvertStringToInputStream {

	public static void main(String[] args) {
		try {
			// Convert the String into InputStream 
			String eurekaUrl = "https://ykyuen.wordpress.com";
			InputStream is = new ByteArrayInputStream(eurekaUrl.getBytes("UTF-8"));
			
			// Use Apache Commons IO to get the content of the InputStream
			System.out.println(IOUtils.toString(is, "UTF-8")); 
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}

Continue reading Java – Convert String to InputStream