Goto labeled statement in Java example
Goto in for cycle Java example source code.
MainClass.java
MainClass.java
public class MainClass {
public static void main(String[] arg) {
String[] arrayOfString = {"nothing", "Hello", "people"
, "bye-bye", "hello", "world!", "end" };
OuterLoop: for (int i = 0;i<6; i++) {
for (int j = 0; j < arrayOfString.length; j++) {
if (arrayOfString[j].equals("world!")) {
continue OuterLoop; // as goto from Csharp, or C/C++
}
System.out.println(arrayOfString[j]);
System.out.println(i);
if (i == 1) {
System.out.println("break");
break OuterLoop;
}
}
}
}
}
/*
nothing
0
Hello
0
people
0
bye-bye
0
hello
0
nothing
1
break
*/
396LW NO topic_id
AD
Další témata ....(Topics)
Brand | Motorola |
Model (codename) | Droid Razr |
Price (cena, včetně DPH v KCZ) | 10800 / 06.2012 |
Display size in Inch (v palcích) | 4.3 |
Display-resolution | 540x960 |
Dotek-typ | capacitive |
CPU typ | TI 4430 |
CPU MHz | 1.2 GB |
CPU core | 2 |
L2 cache | |
RAM | 1024 |
ROM | 15600 |
GPU | SGX540 |
NenaMark2 Benchmark | |
GPU-GLBenchmark | 3299 |
Baterie mAh | 1780 |
Foto MPx | 8 |
Autofocus | AF |
Video | HD video 30 frames/s |
Official Android ICS | Google Android 2.3.5 (Gingerbread) |
CyanogenMod support | |
Dotek-prstů-max | 10 |
Display-ppi | 256 |
Display-retina | 79% |
Networks | |
Connectivity | GSM: 850/900/1800/1900 MHz, EDGE, GPRS 3G: 900/2100 MHz, HSDPA, HSUPA, HSPA+ Bluetooth: 4.0 (EDR, A2DP, FTP, PBAP, AVRCP) Wi-Fi: 802.11b/g/n PC: microUSB, USB 2.0, microHDMI Senzors: proximity, gyroskop, akcelerometr GPS: yes, A-GPS, digital compas |
Note | Super AMOLED Display |
Motorola Droid Razr image
String[] sAr = new String[] {"one","two","three"};
List<String> wordList = Arrays.asList(sAr);
Collections.shuffle( wordList);
String[]myShuffledArray = wordList.toArray(new String[wordList.size()]);
If you change android:versionCode="224" and android:versionName="2.2.4" in AndroidManifest.xml you have to change this in build.gradle file too.
Click on build.gradle in package explorer tree change your new version name and code:
Click on build.gradle in package explorer tree change your new version name and code:
defaultConfig {
applicationId "cz.okhelp.pocasiwidget"
minSdkVersion 11
targetSdkVersion 23
versionCode 224
versionName "2.2.4"
}
private void dialogModeFC() {
try {
final AlertDialog alertDialog = new AlertDialog.Builder(MainActivity.this)
.setTitle(R.string.select_dialog)
//.setItems(
.setSingleChoiceItems(R.array.select_dialog_items, -1
, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
/* User clicked so do some stuff
<item>Happy New Year</item>
<item>Merry Christmas</item>
<item>I Love You</item>
*/
String[] items = getResources().getStringArray(R.array.select_dialog_items);
// list with boolean variables - which is true
// for (int i = 0; i < _listMode.size(); i++) {
// _listMode.set(i, false);
// }
// _listMode.set(which, true);
dialog.dismiss();
// new AlertDialog.Builder(MainActivity.this)
// .setMessage("You selected: " + which + " , " + items[which])
// .show();
}
})
.create();
alertDialog.show();
} catch (Exception e) {
e.printStackTrace();
Toast.makeText(getApplicationContext(), e.getMessage().toString(), Toast.LENGTH_LONG)
.show();//("dialogModeFC", e.getMessage().toString());
}
}// end dialogModeFC
Old code with HashMap
Lint warning:
Use new SparseArray(...) instead for better performance
Issue: Looks for opportunities to replace HashMaps with the more efficient SparseArray
Id: UseSparseArrays
New code with SparseArray
SparseArray methods:
//developer.android.com/reference/android/util/SparseArray.html
Map<Integer, Bitmap> _bitmapCache = new HashMap<Integer, Bitmap>();
private void fillBitmapCache() {
_bitmapCache.put(R.drawable.icon, BitmapFactory.decodeResource(getResources(), R.drawable.icon));
_bitmapCache.put(R.drawable.abstrakt, BitmapFactory.decodeResource(getResources(), R.drawable.abstrakt));
_bitmapCache.put(R.drawable.wallpaper, BitmapFactory.decodeResource(getResources(), R.drawable.wallpaper));
_bitmapCache.put(R.drawable.scissors, BitmapFactory.decodeResource(getResources(),
}
Bitmap bm = _bitmapCache.get(R.drawable.icon);
Lint warning:
Use new SparseArray
Issue: Looks for opportunities to replace HashMaps with the more efficient SparseArray
Id: UseSparseArrays
New code with SparseArray
SparseArray<Bitmap> _bitmapCache = new SparseArray<Bitmap>();
private void fillBitmapCache() {
_bitmapCache.put(R.drawable.icon, BitmapFactory.decodeResource(getResources(), R.drawable.icon));
_bitmapCache.put(R.drawable.abstrakt, BitmapFactory.decodeResource(getResources(), R.drawable.abstrakt));
_bitmapCache.put(R.drawable.wallpaper, BitmapFactory.decodeResource(getResources(), R.drawable.wallpaper));
_bitmapCache.put(R.drawable.scissors, BitmapFactory.decodeResource(getResources(),
}
Bitmap bm = _bitmapCache.get(R.drawable.icon);
SparseArray methods:
//developer.android.com/reference/android/util/SparseArray.html
Editace: 2011-10-04 10:48:30
Počet článků v kategorii: 396
Url:goto-labeled-statement-in-java-example