gudii9
asked on
collection sublist
hi,
I was running following example
import java.util.*;
public class d {
public static void main(String[] args) {
List list = Arrays.asList("one Two three Four five six one three Four".split(" "));
System.out.println("List :"+list);
List sublist = Arrays.asList("three Four".split(" "));
System.out.println("SubLis t :"+sublist);
System.out.println("indexO fSubList: " + Collections.indexOfSubList (list, sublist));
System.out.println("lastIn dexOfSubLi st: "
+ Collections.lastIndexOfSub List(list, sublist));
}
}
from link
http://www.tutorialspoint.com/javaexamples/collection_sublist.htm
Iam getting output as
List :[one-Two, three, Four, five, six, one, three, Four]
SubList :[three, Four]
indexOfSubList: 1
lastIndexOfSubList: 6
I have not understood meaning of sublist its index concept
>> List sublist = Arrays.asList("three Four".split(" "));
what above line do .
Why
indexOfSubList: 1
lastIndexOfSubList: 6
is getting printed.
Any ideas, suggestions, sample code, links, source code highly appreciated. Thanks in advance
I was running following example
import java.util.*;
public class d {
public static void main(String[] args) {
List list = Arrays.asList("one Two three Four five six one three Four".split(" "));
System.out.println("List :"+list);
List sublist = Arrays.asList("three Four".split(" "));
System.out.println("SubLis
System.out.println("indexO
System.out.println("lastIn
+ Collections.lastIndexOfSub
}
}
from link
http://www.tutorialspoint.com/javaexamples/collection_sublist.htm
Iam getting output as
List :[one-Two, three, Four, five, six, one, three, Four]
SubList :[three, Four]
indexOfSubList: 1
lastIndexOfSubList: 6
I have not understood meaning of sublist its index concept
>> List sublist = Arrays.asList("three Four".split(" "));
what above line do .
Why
indexOfSubList: 1
lastIndexOfSubList: 6
is getting printed.
Any ideas, suggestions, sample code, links, source code highly appreciated. Thanks in advance
A 'sublist' is just a list that's part of another list
ASKER
indexOfSubList: 1
lastIndexOfSubList: 6
what is 1 and 6 here . Please advise
lastIndexOfSubList: 6
what is 1 and 6 here . Please advise
ASKER
the link says it should get 2,7 like below..but i am getting 1, 6 not sure why
indexOfSubList: 2
lastIndexOfSubList: 7
indexOfSubList: 2
lastIndexOfSubList: 7
WhyYou must be running different code
indexOfSubList: 1
lastIndexOfSubList: 6
is getting printed.
ASKER
ia m running same code as below
import java.util.*;
public class d {
public static void main(String[] args) {
List list = Arrays.asList("one Two three Four five six one three Four".split(" "));
System.out.println("List :"+list);
List sublist = Arrays.asList("three Four".split(" "));
System.out.println("SubLis t :"+sublist);
System.out.println("indexO fSubList: " + Collections.indexOfSubList (list, sublist));
System.out.println("lastIn dexOfSubLi st: "
+ Collections.lastIndexOfSub List(list, sublist));
}
}
getting output as
List :[one, Two, three, Four, five, six, one, three, Four]
SubList :[three, Four]
indexOfSubList: 2
lastIndexOfSubList: 7
please advise
import java.util.*;
public class d {
public static void main(String[] args) {
List list = Arrays.asList("one Two three Four five six one three Four".split(" "));
System.out.println("List :"+list);
List sublist = Arrays.asList("three Four".split(" "));
System.out.println("SubLis
System.out.println("indexO
System.out.println("lastIn
+ Collections.lastIndexOfSub
}
}
getting output as
List :[one, Two, three, Four, five, six, one, three, Four]
SubList :[three, Four]
indexOfSubList: 2
lastIndexOfSubList: 7
please advise
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.