Hi I want to (multiply,add,etc) vector by scalar value for example myv1 * 3 , I know I can do a function with a forloop , but is there a way of doing this using STL function ? something like the {Algorithm.h :: transform function } ?? Answer: Yes, using std::transform: std::transform(myv1.begin(), myv1.end(), myv1.begin(), [...]
Archive for category Stackoverflow Questions
Storing function pointers
Sep 14
The following uses a simple function pointer, but what if I want to store that function pointer? In that case, what would the variable declaration look like? #include <iostream> #include <vector> using namespace std; double operation(double (*functocall)(double), double wsum); double get_unipolar(double); double get_bipolar(double); int main() { double k = operation(get_bipolar, 2); // how to store [...]
I’ve just read the SUN java code conventions, very nice document btw. and I’ve read this 6.3 Initialization: Try to initialize local variables where they’re declared. The only reason not to initialize a variable where it’s declared is if the initial value depends on some computation occurring first. And I was wondering if Class variables [...]
hi I’m really frustrated, First I have no idea how to code the very complex (make files), so I’m using IDE’s that would ease the job for me like (netbeans , eclipse ,Kdevelop .. etc) i almost tried every thing starting with Emacs (i’m very slow on it and I need autocompletion) Netbeans 6.9.1 (crashes [...]
I really admire java features and I don’t want to give up using it for the next problem: I have a class that might be inherited, and inside of it is a private ArrayList arr; So the setter function is ok , but the getter function return arr; returns the reference to that variable which anyone capable of editing [...]
public static boolean isWebsite(String email) { String regex = “^(https?|ftp|file)://[-a-zA-Z0-9+&@#/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_|]“; CharSequence inputStr = email; Pattern pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE); Matcher matcher = pattern.matcher(inputStr); return matcher.matches(); } public static boolean isWebsite2(String website){ String regex = “[www]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$”; CharSequence inputStr = website; Pattern pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE); Matcher matcher = pattern.matcher(inputStr); return matcher.matches(); }
public static boolean isEmail(String email) { String expression = “^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$”; CharSequence inputStr = email; Pattern pattern = Pattern.compile(expression, Pattern.CASE_INSENSITIVE); Matcher matcher = pattern.matcher(inputStr); return matcher.matches(); }
Write a TreeSet to a File
Sep 14
public static void writeTreeToFile(TreeSet<String> emailTree, String destFile) { try { FileWriter fw = new FileWriter(new File(destFile)); BufferedWriter bw = new BufferedWriter(fw); for (String email : emailTree) { bw.write(email + “\n”); } bw.flush(); bw.close(); } catch (IOException e) { e.printStackTrace(); } }
public static List<String> readFileToList(String file) { List<String> lines = new ArrayList<String>(); File emailsFile = new File(file); try { FileReader fread = new FileReader(emailsFile); BufferedReader buffReader = new BufferedReader(fread); String line = ” “; while ((line = buffReader.readLine()) != null) { lines.add(line); } buffReader.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); [...]
Note: Since November 17th 2011 JANN has been moved to GITHUB.com Well, I’m a beginner and if you’re a beginner you 99% going to be very careful about other beginners like you, so I will try to make it simple and easy. Your Feedback is highly appreciated. Download Download Latest Release and Javadoc Jars. Installation (Using [...]





