java - For loop is acting differently -
here little code
public static void isascending(string[] array){ // todo function verify details of column if column contents ascending for(string a: array) log(a); arrays.sort(array); for(string ao: array) log(ao); } in above, if use first loop, elements in order passed. if put both of them together, no output. (log function same system.out.println)
am making major mistake? cannot see reason second loop not work
log method:
public static void log(string text) { system.out.println(text); } input array: taking array webpage(using selenium). here function doing (it works , gives output expect be) :
public static string[] getemail() { webelement table_element = driver.findelement(by.classname(table_response)); list<webelement> tr_collection=table_element.findelements(by.xpath("//tbody//tr[position()>2]")); int i=0; string[] emails = new string[tr_collection.size()]; for(webelement trelement : tr_collection) { webelement email = trelement.findelement(by.classname("email")); string email_id = email.gettext(); emails[i] = email_id; i++; } return emails; } here how call it:
isascending(getemail());
i tested code, working, make sure openning , closing fors correctly.. here code sample:
public class main { public static void main(string[] args) throws parseexception { string[] array = new string[10]; array[0] = "teste1"; array[1] = "teste2"; array[2] = "asdf3"; array[3] = "dfg4"; array[4] = "xcv"; array[5] = "324dfg"; array[6] = "der"; array[7] = "a"; array[8] = "sdf1"; array[9] = "fgdfg7"; isascending(array); } public static void isascending(string[] array) { (string : array) { system.out.println(a); } system.out.println("----------"); arrays.sort(array); (string ao : array) { system.out.println(ao); } } } output:
teste1 teste2 asdf3 dfg4 xcv 324dfg der sdf1 fgdfg7 ---------- 324dfg asdf3 der dfg4 fgdfg7 sdf1 teste1 teste2 xcv
Comments
Post a Comment