Shuffle List ArrayList Collections Java example
Add and shuffle elements in LinkedList or ArrayList Java basic example.
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
public class MainClass {
public static void main(String[] arg) {
String[] arrayOfString = {"nothing", "Hello", "people"
, "bye-bye", "hello", "world!", "End" };
List<String> arrayList = new LinkedList<String>();
for(String s: arrayOfString)
arrayList.add(s);
Collections.shuffle(arrayList);
System.out.println(arrayList);
}
}
/*
[hello, world!, bye-bye, nothing, people, End, Hello]
*/
396LW NO topic_id
AD
Další témata ....(Topics)
AndroidManifest.xml
<activity android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
android:theme="@android:style/Theme.Translucent" />
Android development
Java float is 32 bit single precision type and used when fractional precision calculation is required.
Java float je 32 bitů veliké číslo sloužící především pro přesný výsledek za desetinnou tečkou například při dělení čísel. Pro větší přesnost použíijte 64 bitový typ Double.
Java float is 32 bit single precision type and used when fractional precision calculation is required.
Java float je 32 bitů veliké číslo sloužící především pro přesný výsledek za desetinnou tečkou například při dělení čísel. Pro větší přesnost použíijte 64 bitový typ Double.
// declaration and assignment of value type float
float x = 18.41785f;
//print formated value
System.out.printf("The value of x is %.3f%n", x); // 18.418
// declaring more variables in single statement
float f1 = 12.4F, f2 = 564.5F, f3 = 14.589F;
// float range of value
System.out.println(Float.MIN_VALUE); // 4E-45
System.out.println(Float.MAX_VALUE); // 4028235E38
// is NaN Not-a-Number
float f = (float) Math.sqrt(-15);
boolean bNaN = Float.isNaN(f);
System.out.print(bNaN); // true
// check if a string is a valid number in Java example
// convert string to float Java example
String sF = "12.8";
float fParse = Float.parseFloat(sF);
// convert strings to numbers
String sFl = "15.48";
float fFromString = (Float.valueOf(sFl)).floatValue();
// float to string in Java example code
Float fObj = new Float(68.5);
String str = fObj.toString();
// else
Float fS = 11.6f;
String sFloat = fS.toString();
// compare two float variables
Float fComp1 = 4.3f;
if(fComp1.equals(4.3f))
System.out.print("true");
// compares the two specified float values in Java example
int i = Float.compare(11.5f, 11.7f); // -1 first < second
// 0 first == second
// 1 first > second
System.out.print(i);
public class MainActivity extends Activity implements OnClickListener {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
LinearLayout layout = (LinearLayout) findViewById(R.id.layout);
RadioGroup radioGroup = new RadioGroup(this);
LinearLayout.LayoutParams p = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.FILL_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT
);
layout.addView(radioGroup, p);
RadioButton radioButtonView = new RadioButton(this);
radioButtonView.setText("RadioButton");
radioButtonView.setOnClickListener(this);
radioGroup.addView(radioButtonView, p);
RadioButton radioButtonView2 = new RadioButton(this);
radioButtonView2.setText("RadioButton2");
radioButtonView2.setOnClickListener(mThisButtonListener);
radioGroup.addView(radioButtonView2, p);
}
public void onClick(View view) {
try {
String s = ((RadioButton) view).getText().toString();
Toast.makeText(MainActivity.this, "This is: " + s,
Toast.LENGTH_LONG).show();
}
catch (Exception e1) {
e1.printStackTrace();
}
}
private OnClickListener mThisButtonListener = new OnClickListener() {
public void onClick(View v) {
String s = ((RadioButton) v).getText().toString();
Toast.makeText(MainActivity.this, "Hello from 2!" + s,
Toast.LENGTH_LONG).show();
}
};
}
private SensorManager mSensorManager;
private PowerManager mPowerManager;
private WindowManager mWindowManager;
private Display mDisplay;
// onCreate
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Get an instance of the SensorManager
mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
// Get an instance of the PowerManager
mPowerManager = (PowerManager) getSystemService(POWER_SERVICE);
// Get an instance of the WindowManager
mWindowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
mDisplay = mWindowManager.getDefaultDisplay();
setContentView(R.layout.main); // main.xml or your xml file name
}
Button, setOnClickListener, Intent.ACTION_VIEW, startActivity Android example.
Button mIdButtonHome = (Button)findViewById(R.id.idButtonHome);
mIdButtonHome.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent browserIntent = new Intent(
Intent.ACTION_VIEW,
Uri.parse("//android.okhelp.cz/category/software/"));
startActivity(browserIntent);
}
});
Editace: 2013-12-09 10:56:48
Počet článků v kategorii: 396
Url:shuffle-list-arraylist-collections-java-example