Recent Notes

Displaying keyword search results 91 - 100
Created by James on August 10, 2009 04:02:25    Last update: August 10, 2009 04:16:31
Function Description Examples length This is actually a property. 'abcd'.length == 4 charAt(int) Return character at given index 'abcd'.charAt(2) == 'c' (index starts from 0) indexOf(string) Return first index of given string 'abcdcdcd'.indexOf('cd') == 2 lastIndexOf(string) Return last index of given string 'abcdcdcd'.lastIndexOf('cd') == 6 substring(beginIndex, endIndex) Return substring starting from beginIndex and ending at endIndex 'abcdcdcd'.substring(1, 3) == 'bc' 'abcdcdcd'.substring(1, 300) == 'bcdcdcd' split(string) Split string into array of strings using given string as delimiter '/home/jsmith/download/js/'.split('/') == ['', 'home', 'jsmith', 'download', 'js', ''] toLowerCase() Convert string to lower case 'AbCd'.toLowerCase() == 'abcd' toUpperCase() Convert string to upper case 'AbCd'.toUpperCase() == 'ABCD'
Created by James on August 09, 2009 03:57:04    Last update: August 09, 2009 03:57:04
Contrary to some online documentation, JavaScript does not seem to support the functions startsWith , endsWith etc. This snippet adds these functions. String.prototype.endsWith = function (a) { ...
Created by Bambi on August 07, 2009 03:06:30    Last update: August 07, 2009 03:06:30
Declaration: String[] s1; String s2[]; int []i; St... Initialization: String[] s3 = new String[5]; int[][] i2 = new i... Iteration: String[] as = { "a", "string", "array" }; f... Sorting: int[] ai = { 6, 7, 8, 1, 2, 3, 4, 5}; java.... Compile error: int[5] i; String s[5]; String[] s2; s2 = ... ArrayIndexOutOfBoundsException: String[] as = { "a", "string", "array" }; for (...
Created by meiu on July 29, 2009 19:30:35    Last update: July 29, 2009 19:30:35
Without the break statement, the Java switch/case block looks very deceptive. Code: public class TestCase { public static void ... Test: C:\tmp>java TestCase No arguments One argume...
Created by James on May 23, 2009 19:46:01    Last update: May 23, 2009 19:49:46
This topic comes up once in a while: I need to generate a random string in JavaScript to get around browser (IE) cacheing. Method 1 (not really random, but a new value every millisecond): function randomString() { return '' + n... Method 2 (generate a random alpha-numerical string): function randomString(length) { var chars =...
Created by Dr. Xi on February 09, 2009 23:14:15    Last update: February 09, 2009 23:14:15
This example demonstrates the general steps in creating a custom Java class loader. Normally a class loader would consult its parent class loader when asked to load a class. If it's not loaded by the parent class loader, then the class loader would try to load the class on its own. This class loader tries to load the requested class on its own first, and delegates to the parent only when a java.lang.SecurityException is thrown (which happens when it tries to load core Java classes such as java.lang.String ). The classes are loaded from CLASSPATH through the getResourceAsStream call. It's important to note that when a class is loaded with a certain class loader, all classes referenced from that class are also loaded through the...
Created by Dr. Xi on November 19, 2008 23:52:22    Last update: November 19, 2008 23:52:22
// Removes the 4-letter words from c static voi...
Created by Dr. Xi on October 16, 2008 23:09:28    Last update: October 17, 2008 03:30:38
import java.io.*; public class TestMSOffice...
Created by Dr. Xi on October 15, 2008 22:20:01    Last update: October 15, 2008 22:20:01
import java.security.MessageDigest; import java...
Created by Dr. Xi on October 15, 2008 18:34:17    Last update: October 15, 2008 18:34:17
class InitializeStringArray { public static...
Previous  2 3 4 5 6 7 8 9 10 11 Next