Thursday, March 6, 2014

There is no big God, java I wrote it there will be a memory leak


 public class TD {
private static String key = "abc";
private static String [] abc = new String [] {"", "A", "B", "C", "D", "E",
"F", "G"};

public static void main (String [] args) {
String strandPrice = "";
dos (strandPrice);
}

private static void dos (String str) {
String [] a = new String [0];
int i = 1;
for (; i = i - 1; i + +) {
String [] b = new String [a.length + 1];
String substr = str.substring (i - 1, str.indexOf ("\ n", i) + 1);
i = str.indexOf ("\ n", i) + 1;
for (int j = 0; j b [j] = a [j];
}
b [a.length] = substr;
a = b;
b = null;
}
String s = str.substring (i - 1, str.length ());
if (s.length ()> 0) {
String [] b = new String [a.length + 1];
for (int j = 0; j b [j] = a [j];
}
b [a.length] = s;
a = b;
b = null;
}
System.out.println ("a.length =" + a.length);
for (int j = 0; j System.out.println ("[" + j + "] =" + a [j]);
}
}
}
<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
Requirements: add serial numbers to string, only one is not added, and remove the last line break

 public class TD {
private static String key = "abc";
private static String [] abc = new String [] {"A", "B", "C", "D", "E", "F",
"G"};

public static void main (String [] args) {
String strandPrice = "afdsa \ nadf \ nasdf \ n";
dos (strandPrice);
}

private static String dos (String str) {
String [] a = new String [0];
int i = 1;
for (; i = i - 1; i + +) {
String [] b = new String [a.length + 1];
String substr = str.substring (i - 1, str.indexOf ("\ n", i) + 1);
i = str.indexOf ("\ n", i) + 1;
for (int j = 0; j b [j] = a [j];
}
b [a.length] = substr;
a = b;
b = null;
}
String s = str.substring (i - 1, str.length ());
if (s.length ()> 0) {
String [] b = new String [a.length + 1];
for (int j = 0; j b [j] = a [j];
}
b [a.length] = s;
a = b;
b = null;
}
for (int j = 0; j 1; j + +) {
a [j] = abc [j] + "," + a [j];
}
. a [a.length - 1] = a [a.length - 1] replace ("\ n", "");
s = "";
for (int j = 0; j s + = a [j];
}
a = null;
return s;
}
}

No comments:

Post a Comment