I’d like to get a string from my ArrayList, but it contains lines from my input fole. How do I split them correctly to have all the elements?
My program looks like this:
private static ArrayList<String> lista;
static void fileReading() {
inp = new LineNumberReader(new BufferedReader(new InputStreamReader(new FileInputStream(inFileNev), "ISO8859-1")));
String sor;
while ((sor = inp.readLine()) != null) {
lista.add(sor);
lista.add(System.getProperty("line.separator"));
}
In another method how do I get this lists only one string and not the line?
EDIT:
Vineet Verma your code is great, but it gets me a great string, and I need to know the indexes of the strings within this, replace them later, and I can’t get it done with only one string.
It’s still not working, if I use this:
String[] temp=null; for(String s : lista) { temp = s.split("\\W+"); }System.out.println(temp);
I get: [Ljava.lang.String;@6ef53890
Wihtin the for I get many : [Ljava.lang.String;@6ef53890
If I use this:
String str ="" ; for(int i=0; i<lista.size(); i++){ str+=lista.get(i)+" "; String[] temp = new String[str.length()]; for(int i=0; i < str.length(); i++) { temp[i]=str.valueOf(i); System.out.println(temp[i]); }
I get only numbers, and can’t figure out how to get the string from str.
Use this code for your problem:
in the other method
If i understand your query correctly then this is the solution