trying to expand range of characters specified in a list object

Posted on 2006-05-02
Last Modified: 2010-03-31
Hi all,
         I have a method called "get_range_alphabets(List lp)"

 I am passing a List object lp of type ('t,x-z,a')

 I want to get the output as ('a','t','x','y',z').
 The output list is in order and it expands on the range x-z.

 Can someone suggest a solution?

 Thanks for your help,

Question by:pkrish
    LVL 92

    Expert Comment

    you can use the split() method of String to split on -
    then use a loop to loop thru the chars

    for (char c=startc; c<=endc;c++)
       // add c to result list
    LVL 3

    Accepted Solution

    * Assuming the elements in the List are of type string always :

        public List get_range_alphabets(List lp)
           List retList = new ArrayList();
            for (int i = 0; i < lp.size(); i++) {
                String elem = (String) lp.get(i);
                if (elem.length() == 1) {
                } else {
                    if (elem.indexOf("-") > 0) {
                        char lower = elem.charAt(0);
                        char upper = elem.charAt(2);
                        for (char p = lower; p <= upper; p++) {

            return retList;

    LVL 86

    Expert Comment

    How is your range specified, i.e. how do you know it's not just individual characters?

    Author Comment


             range is specified as one of the elements in the list "a-d" and that needs to be extracted and expanded along with the individual characters.

    Arun kuttz's solution works fine for me.
    Thanks kuttz and all.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Suggested Solutions

    Title # Comments Views Activity
    withoutTen challenge 14 68
    wordsCount challenge 10 49
    wordsWithout 49 64
    word0 challenge 3 29
    Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
    Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
    Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
    Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now