我正在使用 Jackson 库来解析 JSON:
{
"employees": [
{ "firstName":"John" , "lastName":"Doe" },
{ "firstName":"Anna" , "lastName":"Smith" },
{ "firstName":"Peter" , "lastName":"Jones" }
]
}
Run Code Online (Sandbox Code Playgroud)
这是我正在做的事情:
public void testJackson() throws IOException {
JsonFactory factory = new JsonFactory();
ObjectMapper mapper = new ObjectMapper(factory);
File from = new File("emp.txt"); // JSON object comes from
TypeReference<HashMap<String, Object>> typeRef = new TypeReference<HashMap<String, Object>>() {};
HashMap<String, Object> o = mapper.readValue(from, typeRef);
Employees employees = new Employees();
employees.employees = (List<Employer>)o.get("employees"); // retrieving list of Employer(s)
employees.showEmployer(1); // …Run Code Online (Sandbox Code Playgroud) 我有一个ArrayList<Card> cards = new ArrayList<Card>我需要转换成的TreeSet<Card>.为此我做:
new TreeSet<Card>(cards)
Run Code Online (Sandbox Code Playgroud)
毕竟我的大小TreeSet等于1. Card该类实现Comparable接口.我做错了什么或不做什么?
我有一个Shape定义xml.现在我需要solid color从代码中更改一个,请问如何建议?
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" android:padding="10dp">
<solid android:color="#000000"/>
<corners
android:bottomRightRadius="8dp"
android:bottomLeftRadius="8dp"
android:topLeftRadius="0dp"
android:topRightRadius="0dp"/>
</shape>
Run Code Online (Sandbox Code Playgroud) 我有一个List数据模型,User在下面的例子中,从webService(Retrofit)返回.我把它List分成了元素并逐个发出它们,以filter某种方式向它们发射.然后我需要结合所有的滤波器User并创建List它们.请查看下面的代码,以便更清楚.
webService.getUsers() // returns Observable<List<User>>
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.flatMap(users -> Observable.from(users)) // split the collection of Users, so we can filter them next step
.filter(user -> user.getId() % 2 == 0) // get only Users with even id
// How to transform from here to have a List<User> ?
Run Code Online (Sandbox Code Playgroud) 当你在方法中使用相同的名称和类型声明局部变量时,如实例变量 - 是否意味着实例变量在该方法中变为"不可见"?
public class Test {
Card card;
public void foo(){
Card card = new Card();
card.test();
}
}
Run Code Online (Sandbox Code Playgroud)
所以我在foo()方法中声明并实例化局部变量卡.然后为局部变量调用test()方法.如果我删除了Card card = new Card();test()方法,则调用实例变量.
这是一个例子:
public class Test extends Activity {
Button button;
public int i;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
button = (Button) findViewById(R.id.Button01);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
i = 10; // How can this be possible?
}
});
}
}
Run Code Online (Sandbox Code Playgroud) 例如,我有一个对mItem我的List<mItem> mList集合的对象的引用.这有可能得到一个参考mList使用mItem?
你能解释这个任务吗?这是什么意思?
boolean activityExists = testIntent.resolveActivity(pm) != null;
Run Code Online (Sandbox Code Playgroud) 为什么
calendarCurrent = Calendar.getInstance(Locale.US);
calendarCurrent.get(Calendar.MONTH)
Run Code Online (Sandbox Code Playgroud)
如果现在是12,则返回10?
为什么我得到31而不是3?现在十二月,也就是11月的前一天= 30.
Calendar calendarPreviousMonth = Calendar.getInstance();
calendarPreviousMonth.add(Calendar.MONTH, calendarCurrent.get(Calendar.MONTH) - 1);
System.out.println("Amount of days in month " + calendarPreviousMonth.getActualMaximum(Calendar.DAY_OF_MONTH));
Run Code Online (Sandbox Code Playgroud)
谢谢!