To create a new array or fill it? Java Array Performance

October 12, 2016 Leave a comment

Recently I needed to empty an array to use it later, and asked myself, what is the better option, to create a new one or fill it?
Maybe you have known this long ago, I didn’t. But now, we both know!


int freq[] = new int[256];
//This is better:
                Arrays.fill(freq,0);
//than:
                freq = new int[256];
Categories: Java, Mini-tips, Programación

Configuration Errors on Spring + Wicket

October 11, 2016 Leave a comment

When facing error:
The matching wildcard is strict, but no declaration can be found for element ‘context:component-scan’.

Remember, is a typo somewhere!

If you face error:
No WebApplicationContext found: no ContextLoaderListener registered?

You need to set manually the applicationContext on the setUp() of your test.


public ServletContext getServletContext() {
                ServletContext sc = super.getServletContext();
                XmlWebApplicationContext appCont = new XmlWebApplicationContext();

                appCont.setConfigLocation("classpath:applicationContext.xml");
                appCont.setServletContext(sc);
                appCont.refresh();
                sc.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, appCont);

                return sc;
            }

When error BeanDefinitionStoreException Failed to read candidate component class you got a pom.xml with spring dependencies in conflict.

Categories: Beyond, typo

Read Java input

October 10, 2016 Leave a comment

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = in.nextInt();
        }
        // all ints from 0 to N should be insie array a
    }
Categories: Java, Mini-tips

Split string in sql query – oracle

October 3, 2016 Leave a comment

select regexp_substr(‘MyString,otherString,lastOneStr’,'[^,]+’, 1, level) from dual
connect by regexp_substr(‘MyString,otherString,lastOneStr’, ‘[^,]+’, 1, level) is not null;

–Result :
———-
–MyString
–otherString
–lastOneStr

Categories: Beyond, Mini-tips, Oracle, SQL

Simple way to enable a job in oracle scheduler.

September 29, 2016 Leave a comment

BEGIN
DBMS_SCHEDULER.ENABLE (‘MY_AWESOME_JOB’);
END;
/

Categories: Beyond, Mini-tips, Oracle, plsql

Get duplicates ints in array in 126 Characters with Java 8 and Streams

August 10, 2016 Leave a comment
*(excluding line breaks, and spaces)

int[] GetDuplicates(int[] n) {
    return 
        Arrays.stream(n)
        .distinct()
        .filter(i -> {
            int c = 0;
            for(int x : n)
                c += x==i ? 1 : 0;
            return c>1;
        })
        .toArray();
}
Categories: Java, Mini-tips, Programación, Tips

Split string in oracle sql query

August 1, 2016 1 comment

select regexp_substr('MyString,otherString,lastOneStr','[^,]+', 1, 2) from dual; 
-- Returns 'otherString' String
Categories: Beyond, Mini-tips, Oracle, plsql, SQL, Tips