学习Python并且有点卡住了.
我正在尝试将变量设置为相等,int(stringToInt)或者如果字符串为空则设置为None.
我试着这样做variable = int(stringToInt) or None但是如果字符串为空则会出错而不是仅将其设置为None.
你知道这个吗?
我正在尝试使用XStream反序列化此XML文件,我收到此错误
Exception in thread "main" com.thoughtworks.xstream.converters.ConversionException: Authors : Authors
---- Debugging information ----
message : Authors
cause-exception : com.thoughtworks.xstream.mapper.CannotResolveClassException
cause-message : Authors
class : java.util.ArrayList
required-type : java.util.ArrayList
converter-type : com.thoughtworks.xstream.converters.collections.CollectionConverter
path : /ListOfDBook/DBook/Authors
class[1] : com.test.books.ListOfDBook
converter-type[1] : com.thoughtworks.xstream.converters.reflection.ReflectionConverter
version : null
-------------------------------
at com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:79)
at com.thoughtworks.xstream.core.AbstractReferenceUnmarshaller.convert(AbstractReferenceUnmarshaller.java:65)
at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:66)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.unmarshallField(AbstractReflectionConverter.java:355)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.doUnmarshal(AbstractReflectionConverter.java:306)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.unmarshal(AbstractReflectionConverter.java:234)
at com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:72)
at com.thoughtworks.xstream.core.AbstractReferenceUnmarshaller.convert(AbstractReferenceUnmarshaller.java:65)
at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:66)
at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:50)
at com.thoughtworks.xstream.core.TreeUnmarshaller.start(TreeUnmarshaller.java:134)
at com.thoughtworks.xstream.core.AbstractTreeMarshallingStrategy.unmarshal(AbstractTreeMarshallingStrategy.java:32)
at com.thoughtworks.xstream.XStream.unmarshal(XStream.java:1058)
at com.thoughtworks.xstream.XStream.unmarshal(XStream.java:1042)
at com.thoughtworks.xstream.XStream.fromXML(XStream.java:922)
at com.test.booktest.BookImport.getBooks(BookImport.java:34)
at com.test.booktest.Client.main(Client.java:6)
Caused by: …Run Code Online (Sandbox Code Playgroud) 我想知道这些同步方式之间的区别是什么
List<Integer> intList = Collections.synchronizedList(new ArrayList<Integer>());
synchronized (intList) {
//Stuff
}
Run Code Online (Sandbox Code Playgroud)
并使用对象锁
Object objectLock = new Object();
List<Integer> intList = new ArrayList<Integer>();
synchronized (objectLock) {
//Stuff
}
Run Code Online (Sandbox Code Playgroud) 我有一本书清单
List<Book> books = new ArrayList<Book>();
public class Book {
String name;
List<Author> authors;
}
Run Code Online (Sandbox Code Playgroud)
本书包含作者列表,其中包含ID,姓名和年龄
public class Author {
int ID;
String Name;
int Age;
}
Run Code Online (Sandbox Code Playgroud)
我可以遍历书籍列表并返回BookName = x的位置,但我不知道如何搜索Author并返回Name = y的位置.
我有格式的数据
List<Object[]> data = new ArrayList<Object[]>();
for(Something s : SomeList) {
Object[] tempList = { s.test, s.test2, s.test3 };
data.add(tempList);
}
Run Code Online (Sandbox Code Playgroud)
所以我有一个ArrayList的Objects[].现在我想把ArrayList对象变成一个Object[][]所以我有格式的数据
Object[][] data = { { test, test2, test3 }, { test4, test5, test6 } };
Run Code Online (Sandbox Code Playgroud)
但我不知道该怎么做.
这个ArrayList步骤并不重要,它只是我试图弄清楚时所采取的方向.如果您有更好的方法来获取数据,Object[][]那就太好了.