[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


trying to expand range of characters specified in a list object

Posted on 2006-05-02
Medium Priority
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

ID: 16591938
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

Accepted Solution

arun_kuttz earned 400 total points
ID: 16593094
* 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

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

Author Comment

ID: 16603219

         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.

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
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 …
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month19 days, 7 hours left to enroll

873 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