Category Archives: Array,List,Collections

array, list, collections, java example source code

3,692 views

Shuffle array int string Java Android

String [] arOfStrings = {"one", "two", "three"}; List<String> mListOfStrings = new ArrayList<String>(Arrays.asList(arOfStrings)); Collections.shuffle(mListOfstrings); String str = mListOfStrings.get(2);// 2 is index of pozition an element     int [] arOfInt = {1, 2, 3}; List<Integer> mListOfInt = new ArrayList<Integer>(Arrays.asList(arOfInt)); Collections.shuffle(mListOfInt);

Posted in Android Examples Code, Array,List,Collections | Tagged , | Comments Off on Shuffle array int string Java Android
1,842 views

Java Basic Rules

// file name MyFirstClass.java   import java.util.*; import java.lang.Math; import java.io.*; import javax.swing.*;   public class MyFirstClass{ // start of program public static void main(String[] args) { // basic function main   // variables and calculation int a=2; int b=3; … Continue reading

Posted in Android Examples Code, Array,List,Collections | Tagged , , | Comments Off on Java Basic Rules
3,917 views

String Array of Array Java Example

Set, get string , array of array of strings, Java example code public final static String[][]_arArOfString_1 = { new String[] {"bla","bla","hello world!"}, new String[] {}, new String[] {}, new String[] {}, new String[] {}, new String[] {} }; String sOut … Continue reading

Posted in Android Examples Code, Array,List,Collections | Tagged , , | Comments Off on String Array of Array Java Example
4,941 views

Shuffle Array of String Java Example

String[] sAr = new String[] {"one","two","three"}; List<String> wordList = Arrays.asList(sAr); Collections.shuffle( wordList); String[]myShuffledArray = wordList.toArray(new String[wordList.size()]);

Posted in Android Examples Code, Array,List,Collections | Tagged | Comments Off on Shuffle Array of String Java Example
3,663 views

Save Restore Array List Android Example

int[] mArrayOfInt; String[] mArrayOfString; List<String> mList; public void saveState(Bundle map) { map.putIntArray("mArrayOfInt", mArrayOfInt); map.putStringArray("mArrayOfString", mArrayOfString); map.putStringArrayList("mList", mList); }   public void restoreState(Bundle map) { mArrayOfInt= map.getIntArray("mArrayOfInt"); mArrayOfString = map.getStringArray("mArrayOfString"); mList = map.getStringArrayList("mList");   }

Posted in Android Examples Code, Array,List,Collections | Tagged , , | Comments Off on Save Restore Array List Android Example
3,277 views

R.string to string R.array to array Android

R.string to string Android source code R.array to string [] Android source code String s = getResources().getString(R.string.my_string); // Hello world!! String[] arrayOfStrings = getResources().getStringArray(R.array.my_array); // one, two <xml version="1.0" encoding="utf-8"> <resources> <string-array name="my_array"> <item>one</item> <item>two</item> </string-array> <string name="my_string">Hello world!!</string> </resources>

Posted in Android Examples Code, Array,List,Collections | Tagged , | Comments Off on R.string to string R.array to array Android
29,548 views

SparseArray instead HashMap Android example

Old code with HashMap 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(…) instead for better … Continue reading

Posted in Android Examples Code, Array,List,Collections | Tagged , | Comments Off on SparseArray instead HashMap Android example
2,058 views

LinkedMap HashMap Java

Map<Float,String> linkedHashMap = new LinkedHashMap<Float, String>();   linkedHashMap.put(14.f, "text"); linkedHashMap.put(13.f, "text"); linkedHashMap.put(10.f, "text"); linkedHashMap.put(11.f, "text"); linkedHashMap.put(2.f, "text"); linkedHashMap.put(3.f, "text"); linkedHashMap.put(1.f, "text"); linkedHashMap.put(7.f, "text"); linkedHashMap.put(23.f, "text");   for (Entry<Float,String> entry : linkedHashMap.entrySet()) { System.out.println(entry.getKey()); } 14.0 13.0 10.0 11.0 2.0 3.0 … Continue reading

Posted in Android Examples Code, Array,List,Collections | Tagged | Comments Off on LinkedMap HashMap Java
3,665 views

Iterate HashMap getKey getValue Java Example

HashMap<String,Locale> _mapOfLocale = new HashMap<String,Locale>(); _mapOfLocale.put("French",Locale. FRENCH ); _mapOfLocale.put("German",Locale. GERMAN ); _mapOfLocale.put("Italian",Locale. ITALIAN );   for (Entry<String, Locale> entry : _mapOfLocale.entrySet()) {   System.out.println(entry.getKey()); System.out.println(entry.getValue());   }

Posted in Android Examples Code, Array,List,Collections | Tagged , , | Comments Off on Iterate HashMap getKey getValue Java Example
4,583 views

Map TreeMap get values to array Java Android example

import java.util.Map; import java.util.TreeMap;   public class MainClass { public static void main(String[] arg) {   // english;germany dictionary String[] arrayOfString = { "one;eine", "two;zwei", "two sets of;zwei" , "three;drei", "four;vier" };   Map<String, String> map = new TreeMap<String, String>(); … Continue reading

Posted in Android Examples Code, Array,List,Collections | Tagged , , , , , | Comments Off on Map TreeMap get values to array Java Android example