0
public static void main(String[] args)
{
        loadDependencies ld = new loadDependencies();
        List<String> ls = ld.loadDependenciesFromPom();  
        getAvailableHigherVersions ah = new getAvailableHigherVersions();

        List<List<String>> vl = ah.versionListOnly();
        String previousVersion=null;

        for ( int a=0; a<vl.size();a++) {
            List<String> tmp = vl.get(a);
            for(int i=0; i<ls.size();i++){
                String firstE = ls.get(i);
                for(int j=0;j<tmp.size();j++) {
                    if (i==0  && j==0){
                        //xu.versionUpdate(previousVersion, tmp.get(j));
                        //String previousVersiontt = ls.get(i);
                        System.out.println(firstE + "----" + tmp.get(j));
                    }
                        /*xu.versionUpdate(previousVersion, tmp.get(j));
                        previousVersion=tmp.get(j);*/
                        //System.out.println(previousVersion+"-"+tmp.get(j));
                      //  previousVersion = tmp.get(j);

                }
            }
        }
}

"ls" is a String list. It contains like this

[1,4,5,7]

"vl"is a List of string list. It contains like this

[[1.5,1.6,1.7],[4.1,4.2,4.3],[5.1,5.2],[7.1,7.4]]

what I need to do is first take the 1st element of ls list

1

then i need to get the first element in the vl list

[1.5,1.6,1.7]

then output should be

[1,1.5]

then the next output would be

[1.5,1.6]

likewise iterate through the array. Then next take the 2nd element of ls

4

then it should go like 4,4.1 then 4.1,4.2 likewise until the ls is empty. I tried above code but some times it iterate multiple times. Any hint to fix this issue?

7
  • It has nothing to do with your question but please use the naming conventions: A classname should start with an uppercase letter. It looks like method calls this way. Commented Apr 1, 2019 at 16:24
  • Hints: use forEach type of loops instead, read documentation for the String class to find suitable methods for filtering the right sub-elements Commented Apr 1, 2019 at 16:27
  • The number of elements in ls is always equal to the number of elements in the (outer) list vl? Commented Apr 1, 2019 at 16:28
  • @RobertKock yes it's same Commented Apr 1, 2019 at 16:33
  • What should be printed after [1.6, 1.7]? [4, 4.1] or [1.7, 4]? Commented Apr 1, 2019 at 16:34

3 Answers 3

1

So if I understood well, you want something like this:

for (int a = 0; a < ls.size(); a++)
{
  // Get first element
  String firstE = ls.get(a);

  // Get corresponding vl elements
  List<String> vls = vl.get(a);

  // Now print the elements
  // The first element of vl should be preceeded by the corresponding element in ls
  // The others by the predecessor in the same array
  for (int b = 0; b < vls.size(); b++)
  {
    System.out.print("[");
    if (b == 0)
      System.out.print(firstE);
    else
      System.out.print(vls.get(b - 1));
    System.out.println(", " + vls.get(b) + "]");
  }

}
Sign up to request clarification or add additional context in comments.

Comments

1
for(int i=0;i<ls.size();i++){
   List<String> tmp = vl.get(i);
   System.out.println(ls.get(i)+" "+temp.get(0));
   for(int j=1;j<tem.size()-1;j++){
      System.out.println(temp.get(j)+" "+temp.get(j+1));
   }       
}

Comments

0
for ( int a=0; a<vl.size();a++) {
        List<String> tmp = vl.get(a);
        String firstE = ls.get(a);
            for (int j = 0; j < tmp.size(); j++) {
                if (j == 0) {
                    //xu.versionUpdate(previousVersion, tmp.get(j));
                    //String previousVersiontt = ls.get(i);
                    System.out.println(firstE + "----" + tmp.get(j));
                }
                    /*xu.versionUpdate(previousVersion, tmp.get(j));
                    previousVersion=tmp.get(j);*/
                //System.out.println(previousVersion+"-"+tmp.get(j));
                //  previousVersion = tmp.get(j);

        }
    }
}

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.