我有一个Java Properties对象,我从内存中String加载,以前从实际.properties文件加载到内存中,如下所示:
this.propertyFilesCache.put(file, FileUtils.fileToString(propFile));
Run Code Online (Sandbox Code Playgroud)
util fileToString实际上从文件中读取文本,其余代码将其存储在HashMap被调用的文件中propertyFilesCache.后来,我从HashMapas中读取文件文本String并将其重新加载到Java Properties对象中,如下所示:
String propFileStr = this.propertyFilesCache.get(fileName);
Properties tempProps = new Properties();
try {
tempProps.load(new ByteArrayInputStream(propFileStr.getBytes()));
} catch (Exception e) {
log.debug(e.getMessage());
}
tempProps.setProperty(prop, propVal);
Run Code Online (Sandbox Code Playgroud)
此时,我已经在我的内存属性文件中替换了我的属性,并且我想从Properties对象中获取文本,就像我正在读取File像上面所做的那样的对象.有没有一种简单的方法可以做到这一点,或者我将不得不迭代属性并String手动创建?
我想添加一个对象ArrayList,但每次我添加一个新对象到ArrayList3个属性:objt(name, address, contact)我得到一个错误.
import java.util.ArrayList;
import java.util.Scanner;
public class mainClass {
public static void main(String args[]){
Scanner input = new Scanner(System.in);
System.out.println("Plz enter Name : ");
String name = input.nextLine();
System.out.println("Plz enter Address : ");
String address = input.nextLine();
System.out.println("Plz enter ContactNo : ");
String contact = input.nextLine();
ArrayList<Data> Contacts = new ArrayList<Data>();
Data objt = new Data();
Contacts.add(objt.Data(name, address, contact));
}
}
Run Code Online (Sandbox Code Playgroud)
在这里,Data我正在尝试创建一个对象并将其传递给一个类ArrayList.
public class Data {
private String …Run Code Online (Sandbox Code Playgroud) 我想在我的应用中显示消息通知.在以前的Android版本中,一切都很好,但在Lollipop中,通知背景是白色的.我将此XML代码用于我的通知布局layout_message_notification.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout_messageNotification"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/transparent">
<LinearLayout
android:layout_width="0dp"
android:layout_weight=".2"
android:layout_height="wrap_content"
android:background="@android:color/transparent">
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:scaleType="fitCenter"
android:src="@drawable/message_icon"/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_weight=".8"
android:layout_height="wrap_content"
android:background="@android:color/transparent">
<TextView
android:id="@+id/textView_notification_title"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="right|center_vertical"
android:layout_margin="15dp"/>
</LinearLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
我在棒棒糖中的通知显示如下:

如何将通知背景设置为暗或透明,就像以前的Android版本一样?
notifications android background transparent android-5.0-lollipop
我想Node通过改变它的风格类来改变风格.
Button button = new Button();
button.getStyleClass().add("class1")
button.setOnMouseClicked(new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent mouseEvent) {
button.getStyleClass().add("class2");
}
});
Run Code Online (Sandbox Code Playgroud)
是否有可能逐渐改变风格,使之成为过渡?
如何在JavaFX应用程序中全局设置Font类型?
有什么解决方案可供我使用吗?在JavaFX 8中,默认的Font已经改变,我想使用JavaFX 2.2中使用的相同Font.
我正在尝试按值对RDD进行排序,如果多个值相等,那么我需要通过按字典顺序键这些值.
代码:
JavaPairRDD <String,Long> rddToSort = rddMovieReviewReducedByKey.mapToPair(new PairFunction < Tuple2 < String, MovieReview > , String, Long > () {
@Override
public Tuple2 < String, Long > call(Tuple2 < String, MovieReview > t) throws Exception {
return new Tuple2 < String, Long > (t._1, t._2.count);
}
});
Run Code Online (Sandbox Code Playgroud)
到目前为止我所做的是,使用takeOrdered并提供一个CustomComperator,但由于takeOrdered无法处理大量数据,因此在运行代码时它会一直存在(它占用了操作系统无法处理的大量内存):
List < Tuple2 < String, Long >> rddSorted = rddMovieReviewReducedByKey.mapToPair(new PairFunction < Tuple2 < String, MovieReview > , String, Long > () {
@Override
public Tuple2 …Run Code Online (Sandbox Code Playgroud) 我刚开始使用Java,作为第一个项目,我正在编写一个程序来查找给定数字的根(在本例中为立方根).现在我正在尝试Newton-Ralphson来实现这一目标.这是代码 -
import java.util.Scanner;
import static java.lang.Math.abs;
public class newClass {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Number whose cube root u wanna find:");
Double number = input.nextDouble();
Double epsilon = 0.0001;
Double ans = number/2.00;
while (abs((abs(number) - abs(Math.pow(ans,3))))>epsilon){
System.out.println("in loop");
ans = ans - ((Math.pow(ans,3) - number)/(3*Math.pow(ans,2)));
System.out.println(ans);
if ((number - ans)<=epsilon){
System.out.println(ans);
}
}
//System.out.println(Math.pow(number,1.0/3.0));
}
}
Run Code Online (Sandbox Code Playgroud)
这只能达到11位数,因为它太大了,IDE无法处理.但是,如果我只是使用Math.pow(number,1.0/3.0)它可以工作更大的数字,并立即计算它.
那么,Math.pow()使用的算法是什么给出了即时答案?
我知道我的方法依赖于猜测,我猜math.pow()可能实际上是在计算答案,但是如何?
是什么区别onScroll(),并onFling()在GestureDetector界面?当我打印出事件时,他们会显示完全相同的事情.至少是最后一个onScroll()和onFling().
我注意到的唯一真正的区别是,onScroll()更频繁地调用,总是只有一次.
我想CardView在我的应用程序中实现所有ListView项目都是CardViews.它是否像封装ListView项目XML 一样简单CardView?
我有一个关于"Effective Java"中涵盖的"Builder Pattern"的问题.我们需要一种.build()方法来正确实现模式吗?例如,假设我们有以下类:
public class CoffeeDrink {
private int numEspressoShots;
private short milkType;
private boolean withWhip;
private CoffeeDrink() {
}
public static CoffeeDrink buildNewDrink() {
return new CoffeeDrink();
}
public CoffeeDrink withEspresso(int n) {
this.numEspressoShots = n;
return this;
}
public CoffeeDrink withMilkType(shot t) {
this.milkType = t;
return this;
}
public CoffeeDrink withWhip() {
this.withWhip = true;
return this;
}
}
Run Code Online (Sandbox Code Playgroud)
然后我们如何使用它:
CoffeeDrink c = CoffeeDrink.buildNewDrink()
.withEspresso(2)
.withMilkType(2)
.withWhip();
Run Code Online (Sandbox Code Playgroud)
如果我没有静态内部Builder类,这仍然有效吗?我猜其中一个优点是,CoffeeDrink在.build()调用该方法之前,它不会创建新对象,但我仍在创建一个Builder …
java ×5
android ×3
javafx-2 ×2
javafx-8 ×2
add ×1
algorithm ×1
animation ×1
apache-spark ×1
arraylist ×1
background ×1
builder ×1
hadoop ×1
javafx ×1
properties ×1
string ×1
transparent ×1