3

I'm looking for a way to find the index position of arrays and i want to store that value in String but how can we do this please help me some one

my arrayLists:-

  String[] planets = new String[] { "Mercury","Mercury", "Venus", "Earth", "Mars",
            "Jupiter", "Saturn", "Uranus", "Neptune"};

 String[] Ruppes = new String[] { "100", "200","1000", "300", "400",
            "500", "600", "700", "800"};
1

2 Answers 2

23

you can do by using Arrays.asList

Arrays.asList(planets).indexOf("Mercury") // pass value

Arrays.asList(Rupps).indexOf("100") // pass value

or

Arrays.asList(planets).indexOf(2); //pass index
Sign up to request clarification or add additional context in comments.

3 Comments

no it's showing eroors this line String list = Arrays.asList(planets).indexOf(position);
when i store that value in String there is errors are showing that line
i think we have to do here typecasting
4
private int foundIndex(String query) {
    for (int i = 0; i < planets.length; i++) {
        if (planets[i].equals(query)) {
            return i;
        }
    }
    return -1;
}

... in code:

        int index = foundIndex("Venus");
        if(index!=-1){
            String currentRuppes =Ruppes[index]
        }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.