How to check if a value is a double value in Android (Java)

To check if a value is a double value in Android you can use the snippet below.

Samples

Java (Android) Sample

If you have any questions or suggestions feel free to rate this snippet, post a comment or Contact Us via Email.

Related links:

Please rate this snippet

How to refresh the current Android Fragment

To refresh the current Android Fragment you can use the snippet below. The code must be placed inside the Fragment that needs to be updated. The snippet will call the onCreateView Method of the Fragment.

Samples

Sample Java

If you have any questions or suggestions feel free to rate this snippet, post a comment or Contact Us via Email.

Related links:

Please rate this snippet

How to convert a string to enum in Java

To convert a string to enum in Java you can use the following snippet.

Considering the following enum.

Sample Java

public enum Testenum {
  One,Two,Three,Four
}

you can cast an string to enum like this:

Sample Java

Testenum.valueOf("Two");

Please rate this snippet

How to read a file to string in Java

To read a file to string in Java you can use the following snippet.

Sample Java

public static string readFileToString(FileInputStream _fileInputStream)
{
	try {  
		DataInputStream dataInputStream = new DataInputStream (_fileInputStream);  
		byte[] Bytes = new byte[dataInputStream.available ()];  
		dataInputStream.readFully (Bytes);  
		dataInputStream.close ();  
		String result = new String (Bytes, 0, Bytes.length, "Cp850");  
		return result;  
	}  
	catch (Exception e) {  
		e.printStackTrace();  
		return "";
	} 
}

Please rate this snippet

How to ping in Java

To ping in Java you can use the following snippet.

Sample Java

public static void pingUrl(String url, Integer timeOut)
{
	url = url.replace("http://", "");
	try {  
		InetAddress address = InetAddress.getByName(url);  
		System.out.println("Hostname: " + address.getHostName());  
		System.out.println("IP-Address: " + address.getHostAddress());  
		System.out.println("Reachable in " + ((double)timeOut / (double)1000) + " Seconds: " + address.isReachable(timeOut));  
	}  
	catch (UnknownHostException e) {
		System.err.println("Unable to lookup " + url + "; error: " + e);  
	}  
	catch (IOException e) {  
		System.err.println("Unable to reach " + url);  
	}  
}

Please rate this snippet

How to list the avaiable fonts in Java

To list the avaiable fonts in Java you can use the following snippet.

Sample Java

GraphicsEnvironment g = GraphicsEnvironment.getLocalGraphicsEnvironment();
String fonts[] = g.getAvailableFontFamilyNames();
for (int Counter = 0; Counter < fonts.length;Counter++ ){
	System.out.println(fonts[Counter]);
}

Please rate this snippet

How to join a array to string in Java

To join a array to string in Java you can use the following snippet.

Sample Java

public static String JoinArraylist(List<String> input, String delimiter, Boolean appendToEnd){
	Iterator<String> iteratorString = input.iterator();
	StringBuilder stringBuilder = new StringBuilder();
	for (;;) {
		stringBuilder.append(iteratorString.next());
		if (!iteratorString.hasNext()){ 
			break;
		}
		stringBuilder.append(delimiter);
	}
	if(appendToEnd){
		stringBuilder.append(delimiter);
	}
	return stringBuilder.toString();
}

Please rate this snippet