The KVC method quickly assigns values to Data Objects and kvc assigns values to data objects.
Use the KVC method to quickly assign values to data objects, as shown in the following example:
Declare the following method in the. h file:
-(Id) initWithDic :( NSDictionary *) dic;
In the corresponding. m file
-(Id) initWithDic :( NSDictionary *) dic
{
Self = [superinit];
If (self)
{
[SelfsetValuesForKeysWithDictionary: dic];
}
Returnself;
}
At the same time, the following method is implemented. The implementation content is generally not written (must be implemented; otherwise, KVC cannot be used)
-(Void) setValue :( id) value forUndefinedKey :( NSString *) key
{
}
How to assign values to the Class Object array in the for loop statement in Java?
For example, there is a User class whose class object is user, and the class Object array is
Users [] his length is 10;
In this way, you can use for or foreach to traverse the users array.
Using:
For (int I = 0; I <users. length; I ++ ){
Users [I] = "here is what you want to add" + I; // here is what you want to add
}
In this way, the Class Object array is assigned a value.
How to read data from a file in java, and then assign the value to the object Array
The general implementation function, code writing is not rigorous, and a lot of judgment is not judged. You just need to take a look at how the function is implemented. As for various judgments and verifications, you can do it yourself.
Import java. io. BufferedReader;
Import java. io. File;
Import java. io. FileReader;
Import java. io. IOException;
Import java. util. ArrayList;
Import java. util. List;
Public class FileToArray {
Public static void main (String [] args) throws IOException {
String path = FileToArray. class. getResource ("data.txt"). toString ()
. Substring (6 );
File file = new File (path );
BufferedReader in = new BufferedReader (new FileReader (file ));
List <Student0> students = new ArrayList <Student0> ();
String line;
Int flg = 1;
While (line = in. readLine ())! = Null ){
String [] data = line. split ("");
String name = data [0];
Long id = Long. parseLong (data [1]);
String [] result = new String [data. length-2];
For (int I = 2; I <data. length; I ++ ){
Result [I-2] = data [I];
}
Student0 sdt = new Student0 (name, id, result );
Students. add (sdt );
}
In. close ();
In = null;
File = null;
For (Student0 std: students ){
System. out. println (std. getName () + "" + std. getId ());
For (String res: std. getResult ()){
System. out. println (res );
}
System. out. println ("=================== ");
}
}
}
Class Student0 {
Private String name;
Private long id;
Private String [] result;
Public Student0 (String name, long id, String [] result ){
This. name = name;
This. id = id;
This. result = result;
}
Public String getName (){
Return name;
}
... The remaining full text>