Groovy web console

subscribe to the feed Subscribe
to this
site
Find numeric String from String Array (via #groovywebconsole)
tweet this snippet Tweet
this
script

Find numeric String from String Array

Published 7 months ago by Darrin Johnson with tags find integer numeric selectors
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts
private boolean isNumeric(String value) {
    def numeric = false
    value.toCharArray()?.each { char c ->
        if(Character.isDigit(c)) {
            numeric = true
        } else {
            numeric = false
        }
    }
    numeric
}

String[] selectors = ['test','10','xml']

String limit = selectors?.find { String selector ->
    isNumeric(selector)
}
int result = limit ? Integer.valueOf(limit) : -1

println("Result: ${result}")