2013-04-15 52 views
0

我怎樣才能爲變量的堆棧質量asssignment?如何使質量分配

我聲明的變量

String not_id, not_section, not_steet, not_sqTotal, not_sqLiving, not_sqKitchen, not_flat, not_floor, not_floors, not_text, user_phone1, user_phone2, user_contact, not_region, not_district, not_settle, not_price, not_photo, not_date, not_date_till, not_up, not_premium, not_status; 

名單,我想他們的承滴盤等於"" - 空字符串(或"a",無所謂只是一個例子)

+2

這是不是Java的語言功能。 – noahlz

回答

6
not_id = not_section = ... = not_status = ""; 
0

陣列或其他集合用for循環。任何你能想到的解決方案都會降低到這個水平。如果值不是均勻陣列中的屬於,你必須讓每個你想在實際分配給一些變量賦值一個。這是沒有辦法的。

一般來說,如果你想初始化爲複雜的東西所有的對象,你可以創建與封裝了一個默認的構造函數的包裝類,但是這將是你的情況遠遠更多的工作。例如

Foo a = new Foo(1, 2, 3); 
Foo b = new Foo(1, 2, 3); 

可與

Foo a = new FooW(); 

FooW與調用super(1, 2, 3)默認構造函數擴展Foo所取代。

-1

環路它

for (String s: list) { 
      s=""; 
      //or 
      s="a"; 
     } 
+0

沒有列表... – jamp

+0

「我宣佈變量列表」 ....任何方式祝賀第一個downvote :)。我同意..我的假設是錯誤的。 –

1
String not_id, not_section, not_steet, not_sqTotal, not_sqLiving, not_sqKitchen, not_flat, not_floor, not_floors, not_text, user_phone1, user_phone2, user_contact, not_region, not_district, not_settle, not_price, not_photo, not_date, not_date_till, not_up, not_premium, not_status; 

not_id = not_section = not_steet = not_sqTotal = not_sqLiving = not_sqKitchen = not_flat = not_floor = not_floors = not_text = user_phone1 = user_phone2 = user_contact = not_region = not_district = not_settle = not_price = not_photo = not_date = not_date_till = not_up = not_premium = not_status = ""; 
1
String not_id=not_section=not_steet=not_sqTotal=not_sqLiving=not_sqKitchen=not_flat=not_floor=not_floors=not_text=user_phone1=user_phone2=user_contact=not_region=not_district=not_settle=not_price=not_photo=not_date=not_date_till=not_up=not_premium=not_status="a"; 
+2

這是假定每個字符串,但是'not_id'已聲明。 –