Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Storing String on array java

Tags:

java

android

I want to know if is it possible to Store a String variable on a String array? I cant explain it well but here is what i do:

 String st1 = "",st2 = "",st3 = "",st4 = "";
 String[] str = {st1,st2,st3,st4};

Unfortunately when i use for loop the str gets the value of st1 and st2 and st3 ans st4 not the variable it self..

This is what i want to do exactly on my mind.. Whenever a have a String array for example:

String[] containsValue = { "hi", "hello", "there" };

String strHi, strHello, strThere;
String[] getContainsValue = { strHi, strHello, strThere };

for (int x = 0; x < getContainsValue.length; x++) {
    getContainsValue[x] = containsValue[x];
}

The value of:
strHi = "hi"
strHello = "hello"
strThere = "there";

Basically i want to transfer that value of containsValue[] to 3 String which is strHi, strHello, strThere that are stored in getContainsValue[]. Then use for loop to asign value to them came from containsValue[]. Is this posible? If so then can you give me some format how to do it? thanks..

like image 459
thenewbie Avatar asked Dec 01 '22 05:12

thenewbie


1 Answers

You can use Map<K,V>.

Map<String,String> map=new HashMap<String,String>();
map.put("strHi","hi");
map.put("strHello","hello");
map.put("strThere","there");

System.out.println(map.get("strHello"));
like image 75
KV Prajapati Avatar answered Dec 02 '22 19:12

KV Prajapati