I am reading from an external file in java that consists of strings. I am trying to cut the string short and add them to an array called strings -


private scanner c;  public void openfile3() {     arraylist<string> list3 = new arraylist<string>(7);     try {         c = new scanner(new file("irstudents.txt"));     } catch (exception e) {         system.out.println("could not find file");     }     while (c.hasnextline()) {         list3.add(c.nextline());     }     string[] arraythree = list3.toarray(new string[list3.size()]);     arrays.sort(arraythree);     system.out.println(arrays.tostring(arraythree));     int size = arraythree.length;     string [] names;     for(int j = 0; j<size;j++) {         string word = arraythree[j];         string newword = word.substring(6, 15); 

i trying put characters of string 6-15 string array called names. have put them array called arraythree want put shortened versions of string array called names.

string[] names = new string[size];  (int j = 0; j < size; j++) {   names[j] = arraythree[j].substring(6, math.min(15, arraythree[j].length())); } 

Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

order - Notification for user in user account opencart -