Java array fills, and values print. But, memory always prints after -
Java array fills, and values print. But, memory always prints after -
my project take in , read file load contents array, have user alter , find things it. problem though when go search array prints out contents, along stored in memory. can't figure out how stop because can't figure out is. prints though directory1@27391d.
import java.io.file; import java.io.filenotfoundexception; import java.util.*; public class directory1{ private int size=0; private string[] dval;//sting array public directory1(string directoryfilename){ int size=0;//counter array size int ct=0;//counter dval = new string[size];//new string array file file= new file(directoryfilename); try{ scanner insert = new scanner(file); scanner populate= new scanner(file);//scans file //counts amount of lines array size while(populate.hasnextline()){ string i= populate.nextline(); size++; } dval= new string[size]; //inserts values array for(int i=0;i<dval.length;i++){ string j= insert.nextline(); dval[ct]= j; system.out.println(dval[ct]); ct++; } }catch(filenotfoundexception e) { e.printstacktrace(); } }//end constructor
} when initialize using prints out names in directory prints out in memory.
public class directory{ public static void main(string[] args){ directory1 direct= new directory1("directory.txt"); system.out.println(direct); } }
it's not thought print straight constructor. reason directory1@27391d
beingness printed attempting print object itself. haven't overridden tostring()
, see string
returned the inherited tostring()
method object
.
in other words, method returns string equal value of:
getclass().getname() + '@' + integer.tohexstring(hashcode())
create tostring()
method in directory1
override object
's tostring()
method , create string
trying print in println
statements , homecoming in method.
java arrays memory java.util.scanner
Comments
Post a Comment