ReverseMe Method dose not dicplay.

0 Matic Kržičnik · March 2, 2015

import java.util.*;
public class Linked {
public static void main (String[]args){
String[] things = {"apples","bananas","rukolas","orange","pinapple"};
List list1 = new LinkedList();
for(String x:things)
list1.add(x);

String[] things1 ={"keko","lamp","bad","sleeping"};
List list2 = new LinkedList();
for(String y:things1)
list2.add(y);

list1.addAll(list2);
list2 = null;

printMe(list1);
removeStuff(list1, 2,5);
printMe(list1);
reverseMe(list1);
}
public static void printMe(List l){
for(String i:l)
System.out.printf("%s ",i);
System.out.println();
}
public static void removeStuff(List l,int form,int to){
l.subList(form,to).clear();
}
public static void reverseMe(List l){
ListIterator matic = l.listIterator(l.size());
while (matic.hasPrevious());
System.out.printf("%s ",matic.previous());
}
}

Hi, method reverseMe dose not dicplay?

Post a Reply

Replies

Oldest  Newest  Rating
+1 VISHAL VERMA · March 2, 2015
Your problem lies with the "while" loop
as you put the semicolon after the statement
while (matic.hasPrevious());

this will not have effect on 
System.out.printf("%s ",matic.previous());


as the above statement is out of while scope as it has been terminated by the semicolon
Remove the semicolon and run it again
0 Matic Kržičnik · March 4, 2015
Ty for halp .
  • 1

Java / Android Development

106,964 followers
About

Very popular language used to create desktop applications, website applets, and Android apps.

Links
Moderators
Bucky Roberts Administrator